|
写代码中的遇到报错,检查代码发现的错误原因,记录一下,希望帮到遇到同样困惑的朋友,没有VB版块,发在VBA版块,版主不会删吧。
VB操作EXCEL对像时,方法/属性的归属要区分好,不同于VBA中操作EXCEL.
更改前代码:
xlApp.Cells.EntireRow.Hidden = False
myUsedLastColumn = xlApp.Cells.SpecialCells(xlCellTypeLastCell).Column
ActualLastRow = 0
For i = 1 To myUsedLastColumn
ColumnNo = Replace(Replace(xlApp.Cells(1, i).Address, "$", ""), "1", "")
' myTemp = ThisWorkbook.ActiveSheet.Cells(Rows.Count, ColumnNo).End(xlUp).Row '法一
myTemp = xlApp.Cells(Rows.Count, i).End(xlUp).Row '法二
If myTemp > ActualLastRow Then ActualLastRow = myTemp
Next
Set myTemp = Nothing
更改后代码:
xlApp.Cells.EntireRow.Hidden = False
myUsedLastColumn = xlApp.Cells.SpecialCells(xlCellTypeLastCell).Column
ActualLastRow = 0
For i = 1 To myUsedLastColumn
ColumnNo = Replace(Replace(xlApp.Cells(1, i).Address, "$", ""), "1", "")
' myTemp = ThisWorkbook.ActiveSheet.Cells(Rows.Count, ColumnNo).End(xlUp).Row '法一
RowsCount = xlSheet.Rows.Count
myTemp = xlApp.Cells(RowsCount, i).End(xlUp).Row '法二
If myTemp > ActualLastRow Then ActualLastRow = myTemp
Next
Set myTemp = Nothing
|
|