我試圖清除最後一行之後我從工作表1複製到工作表2中的最後一行工作表2中的數據應始終有50個空白行。VBA Excel:運行時錯誤'1004'object'_Worksheet'的方法'範圍'失敗
Public copied_row_count As Integer
Public ws1 As Worksheet
Public ws2 As Worksheet
Sub Button1_Click()
'Defining the constants below. Change if need based on the value definitions'
Dim Test_Set_Colmn_Number As Integer 'Defining the value of the Cylinder Test Set column number'
Test_Set_Colmn_Number = 23 'W is the current column with the cylinder test set values'
Set ws1 = ThisWorkbook.Sheets("Concrete Log")
Set ws2 = ThisWorkbook.Sheets("Concrete Tracking Graphs")
copied_row_count = 1
Dim j As Integer
j = 0
For i = 1 To Rows.count
If Not IsEmpty(Cells(i, Test_Set_Colmn_Number).Value) Then
ws1.Rows(i).Copy _
ws2.Rows(copied_row_count)
copied_row_count = copied_row_count + 1
End If
Next i
Do While j < 50
ws2.Range("copied_row_count + j:copied_row_count + j").Clear
j = j + 1
Loop
End Sub
我已經收窄誤差降到變量 copied_row_count
及其使用
ws2.Range("copied_row_count + j:copied_row_count + j").Clear
謝謝!