我有這個代碼將檢查我的xls文件中的列E,如果它不是空白,則將該行復制到新的工作表中。但是我找不到如何排除單元格。列C,D,E,F和G以及搜索列。如果我正在運行的宏(在這種情況下是E)中有數據,我想複製該行上的每個單元除C,D,F,G外。這可能嗎?如果值不爲空,Excel將某些單元格複製到新的工作表行
Sub CopyYes()
Dim c As Range
Dim j As Integer
Dim Source As Worksheet
Dim Target As Worksheet
' Change worksheet designations as needed
Set Source = ActiveWorkbook.Worksheets("Sheet1")
Set Target = ActiveWorkbook.Worksheets("Sheet2")
J = 1 ' Start copying to row 1 in target sheet
For Each c In Source.Range("E1:E1000") ' Do 1000 rows
If c <> "" Then
Source.Rows(c.Row).Copy Target.Rows(j)
j = j + 1
End If
Next c
End Sub
難道你不能複製整行,然後刪除你不想要的單元......? – ManishChristian
是的,我一直這樣做,但試圖鞏固儘可能多的步驟,我可以 – Nolemonkey