VBA Code for looping through column and returning value in same row different column

marksc92

New Member
Joined
Sep 4, 2014
Messages
10
Hi, I'm very new to writing Excel Macro's and I feel like it has to be possible, but I cannot find anything on how to do it.

I am looking to have a macro; Open a certain sheet, search through a range of cells and if a certain value "R" is found take a string of text from a different column (same row) and copy that string into a different sheet and paste it at a starting point. Then find the next value "R" in that range and repeat the same process but paste the string on the next row.

Logic:
Search Sheet 1 Column K for "R", once found (say K20) copy text from E20 and paste text on Sheet 2 starting at Cell D36 Then
Search Sheet 1 Column K for "R" once found (say K35) copy text from E35 and paste text on Sheet 2 starting at Cell D37 Then
Repeat a certain number of times (which I have defined as a variable)

I know the process can be done with a Vlookup equation, but I am wanting to do this with VBA and have a list without blank rows...

Hope someone understands and can assist.
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Code:
Sub moveStuff()

    nextRow = 36
    For x = 1 To 30
        If Sheets(1).Cells(x, 11) = "R" Then
            Sheets(2).Cells(nextRow, 4).Value = _
                    Sheets(1).Cells(x, 5).Value
            nextRow = nextRow + 1
        End If
    Next x




End Sub
 
Upvote 0

Forum statistics

Threads
1,214,403
Messages
6,119,309
Members
448,886
Latest member
GBCTeacher

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