我试图编写一个代码,使用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