我試圖編寫一個代碼,使用IF語句提取數據並掃描數據行,如果它有數據,複製它和所有相關數據,如果它不做任何事情。複製時VBA空白單元格抵消數據
我目前的計劃是這樣的
- 如果小區X具有數據複製的數據和所有相關數據,掌握最新的入門後片。然後進入下一行並執行相同的操作。
- 創建一個代碼由一定量的柱(柱宿舍使得這種困難,因爲即時提取的數據是個月)
- 創建宏,主片後從所有的選項卡以數據抵消整個宏該選項卡不是第一個工作表選項卡。
這是我的excel文件。不知道是否有一個地方要在stackoverflow上傳,但在這裏是發送空間。這是我獲取數據的確切格式。這是包含60多個數據標籤的更大的工作文件的一小部分。 http://www.sendspace.com/file/3irz5n
這是我的代碼到目前爲止不起作用。我認爲我有一些錯誤的語法。
編輯:修復了幾個問題。代碼運行正常,除了這一個問題。
這是我目前的代碼。我的源數據中存在空白單元格問題。當存在空白單元格時,它不會複製任何內容並將我的數據抵消到我的主表單中。例如,如果A1列中的數據爲200,則A2爲300.假設在B2中的數據轉到B1因爲B1爲空白。問題代碼始於'將單元格複製到主表單
Sub Test()
Dim imaxrow As Double
Dim ws As Worksheet
For Each ws In Worksheets
'Need to find a way to take data from sheets AFTER macro test sheet
If ws.Name <> "Macro Test Sheet" Then
'Rows of data to be extracted
imaxrow = 22 'Max rows
'Use to offset columns to next dataset
For Each E In Array(0, 11)
'Starting row to copy data
For iRow = 10 To imaxrow
If ws.Cells(iRow, 21).Value = "" Then
'Nothing in this cell.
'Do nothing.
Else
' Copy Cell data to mastersheet
ws.Cells(iRow, 21 + E).Copy Destination:=Worksheets("macro test sheet").Cells(Rows.Count, "F").End(xlUp).Offset(1, 0)
ws.Cells(iRow, 22 + E).Copy Destination:=Worksheets("macro test sheet").Cells(Rows.Count, "G").End(xlUp).Offset(1, 0)
ws.Cells(iRow, 23 + E).Copy Destination:=Worksheets("macro test sheet").Cells(Rows.Count, "H").End(xlUp).Offset(1, 0)
ws.Cells(iRow, 24 + E).Copy Destination:=Worksheets("macro test sheet").Cells(Rows.Count, "I").End(xlUp).Offset(1, 0)
ws.Cells(iRow, 4).Copy Destination:=Worksheets("macro test sheet").Cells(Rows.Count, "C").End(xlUp).Offset(1, 0)
ws.Cells(iRow, 3).Copy Destination:=Worksheets("macro test sheet").Cells(Rows.Count, "B").End(xlUp).Offset(1, 0)
ws.Cells(5, 1).Copy Destination:=Worksheets("macro test sheet").Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
ws.Cells(6, 21 + E).Copy Destination:=Worksheets("macro test sheet").Cells(Rows.Count, "D").End(xlUp).Offset(1, 0)
ws.Cells(7, 21 + E).Copy Destination:=Worksheets("macro test sheet").Cells(Rows.Count, "E").End(xlUp).Offset(1, 0)
End If
Next iRow
Next E
End If
Next ws
End Sub
再次感謝您的幫助和提示。
該代碼運行時沒有錯誤,但沒有信息被拉入主表。我想要的是檢查單元格10,7是否具有信息,如果它提取了這些信息和其他相關信息並將其粘貼到我概述的特定卷中的主表中。 – Reccax