[英]Write cell value from one column to a location specified by other cells
I have a value in Column A which I want to write to a separate sheet, there are column and row numbers which specify the location I want to write that value in the same row as the value in column A. 我在A列中有一个要写入单独工作表的值,有列和行号指定了我要将该值写在与A列中同一行的位置。
For instance the value in A8 has column number "2" in Q8 and row number "118" in S8. 例如,A8中的值在Q8中具有列号“ 2”,在S8中具有行号“ 118”。 So I want to write a formula in the new sheet which puts the value of A8 into cell B118 in the new sheet.
所以我想在新工作表中编写一个公式,将A8的值放入新工作表的单元格B118中。 And for this to go down with all the values in A:A as the first sheet continues to be filled in.
并且随着第一页的填写,这与A:A中的所有值一起下降。
I've tried doing this with sumifs formula here but its not quite working out; 我已经尝试过在这里使用sumifs公式来执行此操作,但效果并不理想;
=IF(SUMIFS(sheet1!$A:$A,sheet1!$Q:$Q,COLUMN(B8),sheet1!$S:$S,ROW(B8))," ",sheet1!$A:$A)
If you want the formula in the new sheet to reference the cell in Sheet1 then: 如果希望新工作表中的公式引用Sheet1中的单元格 ,则:
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
and if you simply want A8 's value transferred to the new sheet, then: 如果您只是想将A8的值转移到新表中,则:
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
EDIT#1: 编辑#1:
Here is a version that will handle the entire column: 这是一个可以处理整个专栏的版本:
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
Here is my answer. 这是我的答案。
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.