×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

How to write this formula in VBA

How to write this formula in VBA

How to write this formula in VBA

(OP)
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!

RE: How to write this formula in VBA

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,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein

RE: How to write this formula in VBA

BTW,

Quote:


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,

glassesJust traded in my OLD subtlety...
for a NUance!tongue

"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein

RE: How to write this formula in VBA

(OP)
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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close