Copy rows based on a condition/rule using VBA

sandor jeges

New Member
Joined
May 26, 2016
Messages
13
This is my current code can anyone help to make it so all rows from the performanceEQ sheet to copy to Output with the rule copy row over if there is a data in cell B2 down, then when there is no more data in the B Column, copy the same row but with the rule IF there is data in cell D2 down until there is no more data - Can anyone help!!!!???

Code:
Sub Stocktransfer()
Set i = Sheets("PerformanceEQ")
Set e = Sheets("Output")
Dim d
Dim j
d = 1
j = 2
 
'FOR THE SELLER
 
Do Until IsEmpty(i.Range("B" & j))
 
If i.Range("B" & j) = "VEAEWP" Then
d = d + 1
e.Rows(d).Value = i.Rows(j).Value
 
End If
j = j + 1
Loop
 
'FOR THE SELLER
 
Do Until IsEmpty(i.Range("D" & j))
 
If i.Range("D" & k) = "VERGRE" Then
d = d + 1
e.Rows(d).Value = i.Rows(d).Value
 
End If
j = j + 1
Loop
 
End Sub
 
Last edited by a moderator:
So we are looking at columns B and D for values

Where do you want columns B data copied to and where do you want column "D" data copied to.

See we needs details here.

Or if you want column A to E copied where on the sheet named "OutPut" do you want these columns pasted to.
 
Upvote 0

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
this might be asking too much... but preferably i want column B & D to actually copy over into Column A - i have 42 rows I am hoping my Output spreadsheet has 84 rows (42 for VEAEWP and 42 for VERGRE) with the below rearrangment of the data

Column E goes to Column B in Output
Column A goes to Column C in Output
Column W goes to Column J in output
 
Upvote 0
Someone else here at Mr. Excel will need to help you.
This has now become something beyond my knowledgebase.
 
Upvote 0
this might be asking too much... but preferably i want column B & D to actually copy over into Column A - i have 42 rows I am hoping my Output spreadsheet has 84 rows with the below rearrangment of the data

Column E goes to Column B in Output
Column A goes to Column C in Output
Column W goes to Column J in Output
And leave everything else as blank???

and the last request I have a number in the column W of Performance EQ - for every row that is now generated for VEAEWP let us say it is positive. As im basically want to duplicate the rows but now with VERGRE in column A but changing the signage to negative for every number in column W????

I know im asking loads but very stuck on this :(
 
Last edited:
Upvote 0
Thanks for your help My answer is this :)

I did just have one more question - i think i can work off your help but for data in Column W... when the macro populates the row with the condition "VERGRE" Column D how can i make it so column W changes the signage???

with this answer i will leave you alone i promise you!
 
Last edited:
Upvote 0
I did notice an issue ill have in the future.
In the code you provided it is referring to Activesheet. I was going to create a front page to this with a button to run the macro. I was also going to ask the macro to read off cell B2 (to replace VEAEWP) and B3 (to replace VERGRE). Can the same code state to look up the worksheet "PerformanceEQ" instead of the active sheet and refer to the Front tab for the two conditions (changing VEAEWP & VERGRE)?
 
Upvote 0

Forum statistics

Threads
1,217,364
Messages
6,136,114
Members
449,993
Latest member
Sphere2215

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