简体   繁体   English

VBA检查2列文字

[英]VBA check 2 columns for text

I have a sheet, that has 2 columns and 36 rows. 我有一张纸,有2列和36行。 Macro should do these things: 1) if cell in row 1, column 1 are not empty and cell in row 1, column 2 is empty macro should stop, else it should continue and after checking all 36 rows it should stop and do SaveAs, if no such values are found. 宏应执行以下操作:1)如果第1行第1列的单元格不为空,而第1行第2列的单元格为空,则宏应停止,否则应继续,并在检查所有36行后应停止并执行SaveAs,如果找不到这样的值。 I found this code and modified a little bit, but it doesn't work as I described: 我找到了这段代码并进行了一些修改,但是它不能像我描述的那样工作:

Sub CheckRows()
    Dim i As Long
    For i = 12 To 47
        'Criteria search
        If Sheets("Claims").Cells(i, 2).Value <> "" Then
            If Sheets("Claims").Cells(i, 3).Value = "" Then
                        Exit Sub
                    Else
            End If
        End If
    Next i
  ActiveWorkbook.SaveAs Filename:="myFile.xlsx", FileFormat:=56
End Sub

Could anyone help me out and tell what's wrong with the code? 谁能帮我一下,告诉代码有什么问题吗? Thanks 谢谢

your looking in column 2 and 3 ,not column 1 and 2 as you wrote... also your starting at row 12, is this correct ? 您在第2列和第3列中查找,而不是您编写的第1列和第2列...也是从第12行开始,这是正确的吗?

Sub CheckRows()
    Dim i As Long
    For i = 12 To 47
        'Criteria search
        If Sheets("Claims").Cells(i, 1).Value <> "" Then
            If Sheets("Claims").Cells(i, 2).Value = "" Then
                        Exit Sub

            End If
        End If
    Next i
  ActiveWorkbook.SaveAs Filename:="myFile.xlsx", FileFormat:=56
End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM