If Statement with multiple criteria + Concatenate Function

WantToMasterExcel

New Member
Joined
Feb 10, 2012
Messages
20
Employee IDFundProperty General ExpenseExpense DescriptionVBA Coded Needed in this Column
JKCPCPCORP March Misc ExpJK - cell phone BillJK - cell phone Bill
LTCPCPCORP Property VisitsLT - taxi from airport to hotelLT - taxi from airport to hotel
SNDCUIDCUI-Fund SN - travel agent feeSN - booking feeSN DCHI DCHUI-Fund SN - travel agent fee
ANCPCPCORP AN - Tours in DCAN - airfare to SeattleAN - airfare to Seattle
RBDCUIDCUI-Fund RB - Museum Tower visitRB - taxi from NOBE tour to hotelRB DCUI DCUI-Fund RB - Museum Tower visit
OSCPCPCORP OS - Meal - SelfOS - Lunch with Donna GaylesOS - Lunch with Donna Gayles
TRRCSRCS-Fund TR - RealShare conference registrationTR - Diverse Investor ForumTR RCS RCS-Fund TR - Real Share conference registration
LMDCUINORE LM - data planLM - PersonalLM - Personal
FWFRCAFRCA Corp FW - ISC conference registrationFW - Spring ConferenceFW FRCA FRCA Corp FW - ISC conference registration
HTTRSILVictor Attending the ConferenceHT - hotel in HoustonHT TRSIL Victor Attending the Conference
DSGALERTower1 DS - BreakfastDS - Dinner w/ VIPsDS GALER Tower1 DS - Breakfast
Required VBA in COLUMN "F":
If the text in Column B is CPCP and the text in column C is Corp, Then Return or copy the value from Column E to Column F
If the text in Column B is DCUI and the text in column C is NORE, Then Return or copy the value from Column E to Column F
For the REST of the Value in Columns B & C, apply CONCATENATE Function(Return the value in Column "F" = Column A "Employee ID" + Column B "Fund" + Column C "Property" + Column D "General Expense"
Also, there are hundreds of ROWS in this Sheet named "Sheet1". Therefore, I need vba to perform till the end of the Last ROW

<tbody>
</tbody>
 
Sub Zacro()
Dim LR As Range

With Sheets("Sheet1")
Set LR = .Cells(.Rows.Count, "A").End(xlUp)
.Range("F2:F" & LR.Row).Formula = " = IF(OR(B2&C2 = CPCPCORP,B2&C2 = DCUINORE),E2,A2&""& B2&""&C2&""&D2))"
End With
End Sub
Now, after this macro, the macros just copies the above formula as it is(IF(OR(B2&C2 = CPCPCORP,B2&C2 = DCUINORE),E2,A2&""& B2&""&C2&""&D2))in Column F. If I put CPCPCORP and DCUINORE in inverted commas, macro gives me "Compilation error: Expected End of Statement Error". Help Needed.
Thanks
 
Upvote 0

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
You need a VBA expert to help you.

Otherwise: if you want to include a " in a string in a macro, then you need to use chr(34):
.Range("F2:F" & LR.Row).Formula = " = IF(OR(B2&C2 = " & chr(34) & "CPCPCORP" & chr(34) & ",B2&C2 = " & chr(34) & "DCUINORE" & chr(34) etcetera

Otherwise the result is refering to the cells in row 2 for ALL rows, so you need some counter to increase the 2's in 3's etcetera.

Again, probably a VBA expert would be better capable to help you.
 
Upvote 0

Forum statistics

Threads
1,214,411
Messages
6,119,346
Members
448,888
Latest member
Arle8907

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