根据公式栏单元格引用将数据移动到工作表2

我需要sheet2中的其他信息,但我不知道如何添加这个。

我在sheet1中有很多数据,但是一切都被分成了三个sections

sheet1的第1部分在A,B,C,D列中,并且包含-date,time,name,last

工作表1的第2部分是数字数据,范围是E至JX列

工作表1的第3部分在范围JY:MV中,并包含结果(来自第2部分)

我已经通过第3节的代码,如果值<1,它将该值复制到F列中的表2中,并从该行第1部分

例:

如果在sheet1 K32中find值0.5,则表2看起来像:

 ABCDF date time name last 0.5 

我需要帮助的任务

1)是否有可能在E栏中的sheet2中查看从哪里find值的sheet1列名称?

2)由于第3节中的每个值都是来自第2节的2个值的结果,所以这两个值是否也可以复制到表2中?

例如

在表1中,K50为0.2,结果来自AA50(2.2)和AC50(2.0),公式使用的是(AA-AC)

是否可以复制表2中的2.2和2.0也基于公式单元格引用?

总结:最终sheet2应该是这样的:

 ABCDEFGH date, time, name, last, Column name where value is found, value, data1, data2 

所以我需要帮助添加列E,G和H

  Sub moveData() Dim rng As Range Dim iniCol As Range Dim i Dim v Dim x Dim myIndex Dim cellVal Dim totalCols Dim sht1 As Worksheet Dim sht2 As Worksheet Dim ABC() 'var to store data from Cols A,B,C in Sheet1 Dim JYJZKA As Range 'var to store data from Cols K,L,M in Sheet1 Set sht1 = Sheets("Sheet1") Set sht2 = Sheets("Sheet2") Set rng = Range("JY1:KB400") Set iniCol = Range("JY1:JY400") totalCols = rng.Columns.Count 'Count the total of columns in the selectec range myIndex = 0 'ini the index for rows in sheet2 For Each i In iniCol x = -1 ABC = Range(Cells(i.Row, 1), Cells(i.Row, 4)) Set JYJZKA = Range(Cells(i.Row, 285), Cells(i.Row, 351)) 'Copy range from A to C sht2.Activate myIndex = Application.WorksheetFunction.CountA(Columns(1)) + 1 For Each v In JYJZKA If v.Value < 1 Then x = x + 1 Range(Cells(myIndex + x, 6), Cells(myIndex + x, 6)).Value = v.Value Range(Cells(myIndex + x, 1), Cells(myIndex + x, 4)).Value = ABC End If Next v 'Paste range equal to copy range. 'Application.CutCopyMode = False sht1.Activate Next i End Sub 

看看这可以让你开始。

我已经将大块数据加载到变体数组中。 这大大加速了单个单元比较的循环。

 Sub section_3_to_Sheet2() Dim r As Long, c As Long, vVALs As Variant, vTMP As Variant With Worksheets("Sheet1") With .Range(.Cells(2, 1), .Cells(Rows.Count, "MV").End(xlUp)) vVALs = .Value2 End With End With With Worksheets("Sheet2") For r = LBound(vVALs, 1) To UBound(vVALs, 1) For c = 285 To UBound(vVALs, 2) If vVALs(r, c) < 1 Then vTMP = Array(vVALs(r, 1), vVALs(r, 2), vVALs(r, 3), vVALs(r, 4), _ "=ADDRESS(" & r + 1 & ", " & c & ", 4, 1, """ & .Name & """)", _ vVALs(r, c), vVALs(r, c - 280)) .Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Resize(1, 7) = vTMP End If Next c Next r End With End Sub 

通常,像这样的数据块有列标题标签,所以我开始你在第2行,而不是你的样本数据可能指示的行1。

原始数据的位置提供了ADDRESSfunction 。

由于E:JX与JY:MV的列数不同,所以我对第二个(例如data2 )值的返回值有些困惑。 我select了一个简单的抵消。