Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to write this formula in VBA

Status
Not open for further replies.

dcompto

Technical User
Jul 5, 2001
751
US
I have hit a wall in writing a portion of an Excel 2016 macro...

Haven't figured out how to write VBA for:
In ws Extracted1,
For every row, compare cell F to cell P,
If F = P, copy F to ws Sorted corresponding row of cell B
If F <> P, copy P to ws Sorted corresponding row of cell B

I have a similar concatenate snippet that works and loops through every row of ws Extracted1 but it does not require an IF statement as I need for the above scenario.

I know how to get the results by formula::
1) Insert one col (G)
2) In col G, type & fill-down the formula
=IF((F2=R2),F2,F2 & " / " & R2)
3) Copy & Paste Values from col G to col F
4) Delete col G

Any help would be greatly appreciated!
 
Hi,

Don't understand why in the first case you have F, P & B, but then you formula has F, R & G???

1) Using your first case, just enter the formula in the first data row of column B of your table in Sorted.

2) Then double-click the HANDLE (lower right-hand cell corner) to propagate the formula through all data cells of your table.

3) Then select the data in column B, right-click > Copy, right-click > Paste Values.

Turn on you macro recorder and record that sequence.

Post back with your recorded code to clean-up help.

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein
AD1D550E-FCB5-4AB6-A3C8-1F86CACE2554_ne1bcz.jpg
 
BTW,
If F = P, copy F to ws Sorted corresponding row of cell B
If F <> P, copy P to ws Sorted corresponding row of cell B

Doesn't that requirement mean that the value in column P is ALWAYS the value that will end up in column B?


Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein
AD1D550E-FCB5-4AB6-A3C8-1F86CACE2554_ne1bcz.jpg
 
Thanks, Skip. I got it done. While my macro code is neither pretty nor efficient, it gets the job done and will save me hours every semester.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top