Conditionally move data from two columns to another column

JJS

Board Regular
Joined
Jul 8, 2009
Messages
81
Hi All,

I have a Sheet where columns B,C and D will have a person's name based on the look up of data from another source. Not every cell is filled (if lookup does not return a match it leaves it blank) in each column.

I originally had this in Column A to compile the data:

Code:
=IF(AND(B2>0,C2="",D2=""),B2,IF(AND(B2="",C2>0,D2=""),C2,IF(AND(B2="",C2="",D2>0),D2,IF(AND(B2>0,C2>0,D2>0),C2,IF(AND(B2>0,C2>0,D2=""),C2,IF(AND(B2="",C2>0,D2>0),C2,IF(AND(B2>0,C2="",D2>0),D2,""))))))
I need to incorporate something like this into a macro but the formula is obviously too long to be recorded.

How can I accomplish the same thing in a macro?

Jeff
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Hi All,

I have a Sheet where columns B,C and D will have a person's name based on the look up of data from another source. Not every cell is filled (if lookup does not return a match it leaves it blank) in each column.

I originally had this in Column A to compile the data:

Code:
=IF(AND(B2>0,C2="",D2=""),B2,IF(AND(B2="",C2>0,D2=""),C2,IF(AND(B2="",C2="",D2>0),D2,IF(AND(B2>0,C2>0,D2>0),C2,IF(AND(B2>0,C2>0,D2=""),C2,IF(AND(B2="",C2>0,D2>0),C2,IF(AND(B2>0,C2="",D2>0),D2,""))))))
I need to incorporate something like this into a macro but the formula is obviously too long to be recorded.

How can I accomplish the same thing in a macro?

Jeff

Why not copy the formula and paste it in a macro:

Code:
Dim lr as long

lr = cells(rows.count,1).End(xlUp).row

With Range("A2:A"&lr)
.Formula = "=IF(AND(B2>0,C2="""",D2=""""),B2,IF(AND(B2="""",C2>0,D2=""""),C2,IF(AND(B2="""",C2="""",D2>0),D2,IF(AND(B2>0,C2>0,D2>0),C2,IF(AND(B2>0,C2>0,D2=""""),C2,IF(AND(B2="""",C2>0,D2>0),C2,IF(AND(B2>0,C2="""",D2>0),D2,""""))))))"
.value = .value
End With
 
Upvote 0

Forum statistics

Threads
1,224,599
Messages
6,179,827
Members
452,946
Latest member
JoseDavid

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