简体   繁体   English

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

[英]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.

相关问题 根据其他单元格中的值显示一个或多个单元格的值 - Displaying value of one cell or multiple cells based on values in other cells Excel,根据第一个单元格的值将一个单元格拆分为其他特定的单元格 - Excel, split one cell into other specific cells based on the value from the first cell 如果单元格值在另一列的列表中,则突出显示一列中的文本单元格 - Highlight text cells in one column if cell value is in a list in a different column 如果其他两个单元格匹配,则在另一个单元格的位置返回第三个单元格的值 - Return a third cell value at the location of another cell if two other cells match 将链接到关键字的多个单元格从一列复制到一个单元格中 - Copy multiple cells linked to a keyword from one column into one cell 将合并后的单元格从其他工作表复制到摘要工作表中的一个单元格中 - Copy merged cells from other sheets into one cell in summary sheet 假设各行彼此对应,请检查一个或多个其他单元格/列中是否存在一个单元格值(关键单元格) - Check if a cell value exists in one or more other cells / columns given that the rows correspond to each other (key cell) 如果其他列的单元格中的值与其他工作表中的值匹配,则链接不同工作表中一列的两个单元格 - Link two cells of a column in different sheets if a value in a cell of other column matches in other sheet 选择列并从其他单元格中找到值 - Select column and find the value from other cell Excel:来自一个单元格的值基于最大值,另一列中有多个条件 - Excel: Value from one cell based on max value with multiple criteria in other column
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM