Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Excel中的VBA检查是否有任何数据输入单元格区域_Vba_Excel - Fatal编程技术网

使用Excel中的VBA检查是否有任何数据输入单元格区域

使用Excel中的VBA检查是否有任何数据输入单元格区域,vba,excel,Vba,Excel,当第一个空行(减去最后一列)被填充时,我试图调用一个子行(新行)。我很难在If语句末尾引用一系列单元格 Sub Data_Added() 'Check if anything has been entered into the first empty row in "Data" Dim sht As Worksheet Dim LastRow As Long Dim LastColumn As Long Dim StartCell As Range

当第一个空行(减去最后一列)被填充时,我试图调用一个子行(新行)。我很难在If语句末尾引用一系列单元格

Sub Data_Added()
'Check if anything has been entered into the first empty row in "Data"

     Dim sht As Worksheet
     Dim LastRow As Long
     Dim LastColumn As Long
     Dim StartCell As Range

     Sheets("Data").Select
     Set sht = Worksheets("Data")
     Set StartCell = Range("A1").End(xlDown).Select

     Worksheets("Data").UsedRange

     LastRow = StartCell.SpecialCells(xlCellTypeLastCell).Row
     LastColumn = StartCell.SpecialCells(xlCellTypeLastCell).Column

     Set InputRange = sht.Range(StartCell, sht.Cells(LastRow + 1, LastColumn - 1))

     If InputRange Is Not Nothing Then
          Call New_Row
     End If
End Sub
我见过有人使用Application.Intersect方法,但我不确定Intersect对于一行单元格是否有意义。不过,我对VBA完全陌生,所以我不知道。现在我在If语句中遇到一个指向“Nothing”的“Invalid use of Object”错误。

Dim y As Long,lastx As Long
Dim y As Long, lastx As Long
Dim sht As Worksheet

y = 1  'Row you want to check

Set sht = ThisWorkbook.Worksheets("Sheet1")
lastx = sht.Cells(y, sht.Columns.Count).End(xlToRight).Column - 1

If WorksheetFunction.CountA(Range(Cells(y, 1), Cells(y, lastx))) <> 0 Then      'Call New_Row when the row you are checking is empty
    Call New_Row
End If
将sht变暗为工作表 y=1'您要检查的行 Set sht=此工作簿。工作表(“表1”) lastx=sht.Cells(y,sht.Columns.Count)。End(xlToRight)。Column-1 如果工作表function.CountA(范围(单元格(y,1),单元格(y,lastx)))为0,则“在检查的行为空时调用新的_行” 打电话到新罗 如果结束
你试过这样的东西吗?

暗y一样长,lastx一样长
将sht变暗为工作表
y=1'您要检查的行
Set sht=此工作簿。工作表(“表1”)
lastx=sht.Cells(y,sht.Columns.Count)。End(xlToRight)。Column-1
如果工作表function.CountA(范围(单元格(y,1),单元格(y,lastx)))为0,则“在检查的行为空时调用新的_行”
打电话到新罗
如果结束

您尝试过类似的方法吗?

请参阅,以获得在区域/工作表/等中查找“最后一个”单元格的更好方法。除了@DavidZemens编写的内容外,
IF
语句的正确语法是
如果Not InputRange is Nothing,则
请参阅,以获得查找“最后一个”单元格的更好方法范围/工作表/etc中的单元格。除@DavidZemens编写的内容外,
IF
语句的正确语法为
IF Not InputRange为Nothing,则