Excel 将一列中的单元格值写入其他单元格指定的位置
我在a列中有一个值,我想将其写入一个单独的工作表,列和行号指定了我想将该值写入与a列中的值相同的行中的位置 例如,A8中的值在Q8中具有列号“2”,在S8中具有行号“118”。所以我想在新的表格中写一个公式,把A8的值放到新表格的B118单元格中。当第一张纸继续被填写时,所有的值都在A:A中 我试过用sumifs公式来做这个,但它不太管用Excel 将一列中的单元格值写入其他单元格指定的位置,excel,vba,excel-formula,excel-2013,formulas,Excel,Vba,Excel Formula,Excel 2013,Formulas,我在a列中有一个值,我想将其写入一个单独的工作表,列和行号指定了我想将该值写入与a列中的值相同的行中的位置 例如,A8中的值在Q8中具有列号“2”,在S8中具有行号“118”。所以我想在新的表格中写一个公式,把A8的值放到新表格的B118单元格中。当第一张纸继续被填写时,所有的值都在A:A中 我试过用sumifs公式来做这个,但它不太管用 =IF(SUMIFS(sheet1!$A:$A,sheet1!$Q:$Q,COLUMN(B8),sheet1!$S:$S,ROW(B8))," ",sheet
=IF(SUMIFS(sheet1!$A:$A,sheet1!$Q:$Q,COLUMN(B8),sheet1!$S:$S,ROW(B8))," ",sheet1!$A:$A)
如果希望新工作表中的公式引用工作表1中的单元格,则: 如果您只是想将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
编辑#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-marine3()
尺寸cl为长,rw为长,源为字符串
暗淡的i一样长,N一样长
N=单元格(Rows.Count,“A”)。结束(xlUp)。行
对于i=8到N
cl=范围(“Q”和i)。值
rw=范围(“S”和i).值
如果cl 0和rw 0,则
板材(“新”)。单元格(rw,cl)。值=范围(“A”和i)。值
如果结束
接下来我
端接头
这是我的答案
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
谢谢你的回复!不幸的是,我不需要只传输第8行数据,我的数据恰好从8开始,然后我需要A:A中的所有值,直到数据传输为止,这将随着一年中表格的填写而增长。有没有一种方法可以对整个列范围执行此操作,以便Q:Q、S:S、a:a动态地知道要停止的最后一行?@JRBB是否要扩展marine()或marine2()?嗯,不确定,如果我们使用marine2,那么我可以有一个按钮来运行该子行,擦拭新工作表,然后将所有值转移到需要的位置,从而进行更新?@JRBB查看我的编辑#1非常感谢Gary的学生,这项工作非常出色。当我重新运行子模块时,我现在将调整它以清除先前存在的单元格内容。令人遗憾的是,这在“sht2.Cells(Q,S).Value=A”行中出现了一个错误,我同意Gary的学生的回答,因为这对我来说已经完成了工作。感谢您抽出时间回答我的问题,尽管埃尔伯特!
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