using information in one cell to copy values in cells above to other cells

jluensman

New Member
Joined
Jul 19, 2024
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hello-

I am trying to use a macro to look at the text in one cell and copy values of other cells elsewhere based on that value.

In the example below, I would want the macro to look at column A and find the word "Price". Once it finds "Price" in A13, I would like to move A12 to J2, A11 to I2, A10 to H2, A9 to G2 and A8 to F2. Since Example 1 does not have "Price" anywhere in it, I would like it to be skipped.

1721392083552.png
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Hi,

would something like this do what you need ?

VBA Code:
Sub test()

Dim SrcRow, SrcRange As Variant
Dim x, op, lastrow As Long

lastrow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row
op = 2 'start row for output

For x = 3 To lastrow

    If Range("A" & x) = "Price" Then
    
        Set SrcRange = Range(Cells(x - 5, 1), Cells(x - 1, 1))
        SrcRow = SrcRange.Value
        Transposerow = Application.Transpose(SrcRow)
        Range(Cells(op, 6), Cells(op, 10)).Value = Transposerow
        op = op + 1
    End If

Next x


End Sub

cheers
Rob
 
Upvote 0
Solution
Hi,

would something like this do what you need ?

VBA Code:
Sub test()

Dim SrcRow, SrcRange As Variant
Dim x, op, lastrow As Long

lastrow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row
op = 2 'start row for output

For x = 3 To lastrow

    If Range("A" & x) = "Price" Then
   
        Set SrcRange = Range(Cells(x - 5, 1), Cells(x - 1, 1))
        SrcRow = SrcRange.Value
        Transposerow = Application.Transpose(SrcRow)
        Range(Cells(op, 6), Cells(op, 10)).Value = Transposerow
        op = op + 1
    End If

Next x


End Sub

cheers
Rob
Hey Rob-

Yes this worked. Thank you.
 
Upvote 0
thanks for feedback, glad we could help.

Rob
 
Upvote 0

Forum statistics

Threads
1,224,462
Messages
6,178,815
Members
452,881
Latest member
motivationgyan

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top