将一列的单元格值写入其他单元格指定的位置

Write cell value from one column to a location specified by other cells

我在 A 列中有一个值,我想将其写入单独的 sheet,列号和行号指定了我想将该值写入与A 列

例如,A8 中的值在 Q8 中具有列号“2”,在 S8 中具有行号“118”。所以我想在新 sheet 中编写一个公式,将 A8 的值放入新 sheet 中的单元格 B118 中。为了使 A:A 中的所有值下降,因为第一个 sheet 继续被填充。

我在这里尝试使用 sumifs 公式进行此操作,但效果不佳;

=IF(SUMIFS(sheet1!$A:$A,sheet1!$Q:$Q,COLUMN(B8),sheet1!$S:$S,ROW(B8))," ",sheet1!$A:$A)

如果您希望新 sheet 中的公式引用 Sheet1 中的 cell 那么:

Sub marine()
   Dim cl As Long, rw As Long, source As String

   cl = Range("Q8").Value
   rw = Range("S8").Value

   Sheets("new").Cells(rw, cl).Formula = "=Sheet1!A8"

End Sub

并且如果您只是想将A8转移到新的sheet,那么:

Sub marine2()
   Dim cl As Long, rw As Long, source As String

   cl = Range("Q8").Value
   rw = Range("S8").Value

   Sheets("new").Cells(rw, cl).Value = Range("A8").Value

End Sub

编辑#1:

这是一个可以处理整个专栏的版本:

Sub marine3()
   Dim cl As Long, rw As Long, source As String
   Dim i As Long, N As Long

   N = Cells(Rows.Count, "A").End(xlUp).Row

   For i = 8 To N
      cl = Range("Q" & i).Value
      rw = Range("S" & i).Value
      If cl <> 0 And rw <> 0 Then
         Sheets("new").Cells(rw, cl).Value = Range("A" & i).Value
      End If
   Next i
End Sub

这是我的答案。

Sub movindData()
    'take all the data from sheet1 and move it to sheet2
    Dim sht2 As Worksheet
    Dim r
    Dim c
    Dim i
    Dim rng As Range
    Dim A 'for each value in column A
    Dim Q 'for each value in column Q (the column)
    Dim S 'for each value in column S (the row)


    r = Range("A1").End(xlDown).Row 'the botton of columns A, the last row
                                    'I take the inicial cells as a A1, but you
                                    'can change it as you need.
    c = 1 'the column A

    Set rng = Range(Cells(1, 1), Cells(r, c)) 'this takes just the range with the data in columns A
    Set sht2 = Sheets("Sheet2") 

    For Each i In rng
        A = i.Value 'Store the value of every cell in column A
        Q = i.Offset(0, 16).Value 'Store the value of every cell in column Q (the destination column in sheet2)
        S = i.Offset(0, 18).Value 'Store the value of every cell in column s (the destination row in sheet2)
        sht2.Cells(Q, S).Value = A
    Next i
End Sub