A test export showing 2 sample points as they come from the software我有100多个样本点的数据导出到excel中。我想将这些数据中的特定信息提取到一个汇总表中。每个样本点导出为离散表,并且表每11行重复一次。例如,如果b4包含样品1的分析物(A)值,则b15包含样品2的(A)值
我希望能够提取所有的A值,以及其他值。总共发现6个分析物,跨行3-7列B-D,然后向下重复11个单元格以创建表格(从11个单元格向下复制数据到新表的第二行,依此类推) This is an example from a previous report where I manually pulled all of the data and created a table
我已经成功地创建了一个宏来将这些数据从第一个样本中拉入到第二个工作表中,我相信我需要一个重复的next函数,但我不知道如何操作
Private Sub CommandButton1_Click()
Sheets("Sheet1").Range("D3").Copy Destination:=Sheets("Sheet2").Range("B2")
Sheets("Sheet1").Range("B4").Copy Destination:=Sheets("Sheet2").Range("C2")
Sheets("Sheet1").Range("B5").Copy Destination:=Sheets("Sheet2").Range("D2")
Sheets("Sheet1").Range("B6").Copy Destination:=Sheets("Sheet2").Range("E2")
Sheets("Sheet1").Range("B7").Copy Destination:=Sheets("Sheet2").Range("F2")
End Sub这是我目前的宏图
发布于 2019-10-25 20:42:30
根据需求,您可以执行以下操作:
Private Sub CommandButton1_Click()
Dim sourcesheet As Worksheet
Dim destsheet As Worksheet
Dim repeat_x_times As Long, loopcounter As Long
Dim onelocation As Long, spread As Long
Dim locations As Variant
Dim locationlist As String
'---------------------------------------
' edit these as you see fit
'---------------------------------------
Set sourcesheet = Sheets("Sheet1")
Set destsheet = Sheets("Sheet2")
locationlist = "D3,B4,B5,B6,B7"
spread = 11
repeat_x_times = 6
'---------------------------------------
locations = Split(locationlist, ",")
With sourcesheet
For loopcounter = 1 To repeat_x_times
For onelocation = 0 To UBound(locations)
.Range(locations(onelocation)).offset((loopcounter - 1) * spread, 0).Copy destsheet.Cells(loopcounter, 2 + onelocation)
'or if you don't need formatting, just values (much quicker):
'destsheet.Cells(loopcounter, 2 + onelocation).Value = .Range(locations(onelocation)).offset((loopcounter - 1) * spread, 0).Value
Next
Next
End With
End Sub我已经根据您的需要轻松地进行了配置,只需编辑变量:
locationlist是您要拾取的单元格的列表,按照您希望它们在sheet2上输出的顺序。
spread是重复之间的偏移量。
repeat_x_times是您想要输出的行数。
我使用的copy语句与您现有的代码类似,但如果您不想复制格式化等,您可以只使用一个值开关。我已经注释掉了代码,但是如果你想使用它,可以取消注释,然后注释掉copy行。
https://stackoverflow.com/questions/58557000
复制相似问题