View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
gocush[_4_] gocush[_4_] is offline
external usenet poster
 
Posts: 1
Default If statement with multiple conditions


If you want to do this with code, try the following ( adjusting th
columns as needed):

I set this up as follows
A2:A100 is named SalaryType
B2:B100 contains years of service
C2:C100 will contain the "Results" ie the text you want
X2:X11 is named "Text" and contains the 10 possible "answers"
such as "Two weeks" or "5 Days", "6 Days"......

There will be 2 salary types: 0 or 5
There will be 5 longevity categories: 1-5
By adding the two we get 1-10

The INDEX function in the last code line looks up the nth (1-10) valu
in the "Text" range and returns the value to column C
(which is offset 2 columns from the Salary col--adjust as needed)

The VOID line allows for rows in your database that may be emplty


Sub VacationTime()

Dim oCell As Range
Dim x As Integer
Dim y As Integer

For Each oCell In Range("SalaryType")
'Assign Salarytype category
Select Case oCell.Value
Case 1 To 3
x = 0
Case Is 3
x = 5
Case Else
GoTo VOID
End Select
'Assign longevity category
Select Case oCell.Offset(0, 1).Value 'change "1" to match th
column offset to Years col
Case 0 To 4
y = 1
Case 5 To 9
y = 2
Case 10 To 14
y = 3
Case 15 To 19
y = 4
Case Is 19
y = 5
End Select

oCell.Offset(0, 2) = Application.Index(Range("Text"), x + y)
'change the "2" to an empty column offset fro
SalaryType
VOID:
Next
End Su

-----------------------------------------------
~~ Message posted from http://www.ExcelTip.com
~~View and post usenet messages directly from http://www.ExcelForum.com