单元格(i,j)。值无法比较字符串

时间:2018-09-02 10:27:53

标签: loops find compare cell

我有一个范围A的单元格,其中包含帐户199。我正在使用.Cells(rownum,1)查找字符串。

If ActiveWorkbook.Worksheets("Startsheet").Cells(rownum, 1).Value = "Account 199" Then 
<DO SOMEJOB> 
End If

在特定的工作表中,在rownum的实际位置中,使用IF的比较不起作用并且作业没有完成, 但, 当在实际位置上方插入单独的一行时,使用IF进行的上述比较将正常进行。

尝试通过Range和Cells函数将.Value替换为.Text,但没有结果。

188帐户或177帐户似乎不错,但199帐户却不行!

请提出任何建议。

 Sub test()
Dim rownum As Long
Dim startrow As Long
Dim endrow As Long
Dim lastrow As Long
Dim ant As Long
Dim wasp As Long
lastrow = Worksheets("Startsheet").Range("A65536").End(xlUp).Row
With ActiveWorkbook.Worksheets("StartSheet").Range("A1:A" & lastrow)
wasp = 1
ant = 0
startrow = 0
For rownum = 1 To lastrow
Do
''''''''''''''''''Account 199'''''''''''''''''''''''''''''''''''''''''''''
If ActiveWorkbook.Worksheets("Startsheet").Cells(rownum, 1).Value Like "Account 199" Then
      startrow = rownum
      wasp = startrow
      ant = 0
   End If

    rownum = rownum + 1
    wasp = wasp + 1

If (ant = 2) Then Exit For
Loop Until .Cells(wasp, 1).Value = "@01\QPosted@"
If startrow <> 0 Then
ant = ant + 1
End If

endrow = rownum
rownum = rownum + 1

If ant = 2 Then
Worksheets("StartSheet").Range(startrow & ":" & wasp - 2).Copy
Sheets("Endsheet").Select
Range("A2").Select
ActiveSheet.Paste
End If
Next rownum
End With
End Sub

https://drive.google.com/drive/folders/1yi1dwOoprxrXaNs3WxU0LyIfQzDqRqPP?usp=sharing

Image is here FYI

0 个答案:

没有答案