excel - 比较字符串值VBA时,如果语句跳过正文
问题描述
我正在尝试根据关键字删除列。即使字符串完全匹配并且变量类型匹配,if 语句也会跳过正文。我在行周围添加了星号,这给我带来了麻烦以及我的手表结果。如果有人能给我一个发生这种情况的原因,我将不胜感激。
Dim sourcebook As Workbook
Dim sourcesheet As Worksheet
Dim lastcol As Long
'Dim currentCell As String
Set sourcebook = ActiveWorkbook
Set sourcesheet = sourcebook.Sheets("Sheet1")
Set ws = Application.activesheet
With ws
If WorksheetFunction.CountA(Cells) > 0 Then
lastcol = Cells.Find(what:="*", searchorder:=xlByColumns, searchdirection:=xlPrevious).Column
End If
End With
Set chkrng = activesheet.Range("E1", Cells(1, lastcol))
'time keywords
t1 = "Min. Time L1 Phase"
t2 = "Max. TimeL1 Phase"
t3 = "Min. TimeL2 Phase"
t4 = "Max. TimeL2 Phase"
t5 = "Min. TimeL3 Phase"
t6 = "Max. TimeL3 Phase"
t7 = "Min. Time3 Phase Sy..."
t8 = "Max. Time3 Phase Sy..."
For Each cell In chkrng
***If cell.Value = t1 Then cell.EntireColumn.Delete***
Next
Watch : :cell.Value : "Min. Time L1 Phase" : Variant/String
Watch : :t1 : "Min. Time L1 Phase" : Variant/String :
更新:我无法修复原始代码,但会附上我所做的,以防其他人遇到类似问题。
For i = 4 To lastcol - 1
CurrValue = Range("A1").Offset(0, i).Value
If InStr(1, CurrValue, "Time") > 0 Then
Columns(i + 1).Delete
End If
Next i
解决方案
推荐阅读
- sql - 当收到“列名不明确”错误时,您在 Google BigQuery 中使用什么格式来指定 table.column?
- django - 如何在外部 iframe 中嵌入 Django 网站
- c# - 如何将 YouTube 本地化(翻译)添加到我的 C# YouTube 视频上传器?
- javascript - 验证时用另一个替换字符
- c# - When I Debug my WPF Project Visual Studio runs the wrong Project/Is just blank
- sql - 多个 unpivot 和 pivot 在同一列名上
- laravel - 如何在不使用策略所属模型的索引上使用策略?
- c - 如何在c中对数组进行切片
- angular - 角度 - 材料
在测试中不可见 - java - Redisson getLock() 对分布式锁的使用安全吗?