Forum Discussion

SamSh84's avatar
SamSh84
Copper Contributor
May 06, 2022
Solved

Copy using cell name column

Hello ,

How can I check the number of the cell from right (B2,B3,B4......) and copy the content of cell (A2,A3,A4....)from right to the left side based on the cell number (B2,B3,B4,....) from right  , using a macro or VBA code .

 

note :

we can combine 2 files together in same sheet.

 

thanks.

 

 

  • SamSh84 

    Here is such a macro:

    Sub FillData()
        Dim w1 As Worksheet
        Dim w2 As Worksheet
        Dim r As Long
        Dim m As Long
        Application.ScreenUpdating = False
        ' Change the names of the sheets as needed
        Set w1 = Worksheets("Sheet1")
        Set w2 = Worksheets("Sheet2")
        m = w2.Range("B" & w2.Rows.Count).End(xlUp).Row
        For r = 2 To m
            w1.Range(w2.Range("B" & r).Value).Value = w2.Range("A" & r).Value
        Next r
        Application.ScreenUpdating = True
    End Sub

4 Replies

  • SamSh84 

    Here is such a macro:

    Sub FillData()
        Dim w1 As Worksheet
        Dim w2 As Worksheet
        Dim r As Long
        Dim m As Long
        Application.ScreenUpdating = False
        ' Change the names of the sheets as needed
        Set w1 = Worksheets("Sheet1")
        Set w2 = Worksheets("Sheet2")
        m = w2.Range("B" & w2.Rows.Count).End(xlUp).Row
        For r = 2 To m
            w1.Range(w2.Range("B" & r).Value).Value = w2.Range("A" & r).Value
        Next r
        Application.ScreenUpdating = True
    End Sub

Resources