Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

If statements for hourly rates based on different names

0

 If Cell A1 contains "Name" then A2 (contains a formula for hourly rate that depends on name in A1) 

Ex: IF A1=John,  then A2 =(hours x$5/hr) vs if A1=Bob, then A2=(hours x$7/hr) I already have the formula set up calculate time & hourly rates. But I have to manually change the hourly rate if tbe name changes. 

This is the formula I have in A2, which gives me hourly total. But I'd like the rates ($5 vs $7) to be recognized based on text in A1

John= $5/hr 

=IF(J106=0,0,IF((J106>1),J106*5,5))

Bob=$7/hr

=IF(J106=0,0,IF((J106>1),J106*7,7))

Is this possible?  

Answer
Discuss

Answers

0

 If you only have John & Bob you could try modifying your IF formula to:

=IF(J106=0, 0, IF((A1 = "John", J106*5, IF(A1 = "Bob", J106*7,0)))

If you have multiple employees the solution will take more work - and we would need to know how many employees could involved.

In your formula ~  =IF(J106=0,0,IF((J106>1),J106*5,5))  ~ I don't see the need for the second IF. If the hours (J106) are not 0, then they will be greater than 0. I can't imagine an instance where there would be negative hours. If the person owes money back that should be handled in another part of the sheet. Also, without a sample file I don't understand the reason for the "5" (or 7) at the end.

Discuss
0

PM

You could use VLOOKUP to do this (especially if combined with Data Validation and tables/ named ranges).

You didn't attach an Excel file but in the attached file you'll see two yellow cells in Sheet1. There's a drop-down list to change the name and that will cause the value in A2 to change, according to the rate. The formula in A2 could be:

=A3*VLOOKUP(A1,'Employee rates'!A1:B4,2,FALSE)
where A3 is the worked hours (the second yellow cell- change that and A2 changes too).and the bit 'Employee rates'!A1:B4 points to cells in the sheet called "Employee rates'". The VLOOKUP formula means "lookup the name (in cell A1) in that area and when you find it,take the value from the column number 2 in that area"

In fact I've made that arrea a named table "RatesTable" and the cell A1 has the name "EmployeeName". The formula in A2 becomes:

=A3*VLOOKUP(EmployeeName,RatesTable,2,FALSE)
which is more readable. You can refer to Name Manager (under Formulas in the ribbon) to see which cells those things mean. You could also give cell A3 a name e.g. Hours to make it even easier.

Note that Data Validation (List) has been used to give the dropdown in A1 of Sheet1. Add another name below the Rates Table and you'll see that the dropdown list changes to suit.

You may frind some of Don's tutorials helpful to understand this- e.g. Vlookup with a Range of Numbers in Excel and Excel Data Validation - Limit What a User Can Enter into a Cell.

Hope this helps rather than confuses.

Discuss


Answer the Question

You must create an account to use the forum. Create an Account or Login