简体   繁体   English

Excel 2010,来自不同工作簿的VBA无法返回IsEmpty值

[英]Excel 2010, VBA From Different Workbook Cannot Return IsEmpty Value

The below code should delete a row if Cell(1,2) is empty. 如果Cell(1,2)为空,则以下代码应删除一行。 When being run within the workbook which contains the code, it accurately returns the IsEmpty function. 在包含代码的工作簿中运行时,它将准确地返回IsEmpty函数。 When being run from an ActiveSheet in another workbook, it will not return the IsEmpty function. 从另一个工作簿中的ActiveSheet运行时,它将不会返回IsEmpty函数。 Is there a solution for this? 有解决方案吗?

Public Sub formatSheet()
Dim test As Boolean
test = IsEmpty(ActiveSheet.Cells(1, 2))
'Removes header lines
Do Until test = False
    Rows("1:1").Delete
    test = IsEmpty(ActiveSheet.Cells(1, 2))
Loop
End Sub

You need to activate the workbook and worksheet you want to delete the row from first: 您需要先激活要从中删除行的工作簿和工作表:

How do i activate a specific workbook and a specific sheet? 如何激活特定的工作簿和特定的工作表?

Hope that link helps! 希望链接有所帮助!

You don't need to activate the spreadsheet you want it to run on, but you do need to refer to the sheet and workbook. 您无需激活要在其上运行的电子表格,但是需要参考工作表和工作簿。 To do this without creating objects and associated pointers, try this code: 为此,无需创建对象和关联的指针,请尝试以下代码:

    test = IsEmpty(Workbook("NameOfWorkBookYouWishToCheck").Sheets("NameOfSheetYouWishToCheck").Cells(1, 2))

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

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