![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
New Member
Join Date: May 2002
Location: Copenhagen, Denmark
Posts: 2
|
I am new in the field of VBA and would like to advance my knowledge on this area. Upon doing this, I was wondering how to make a macro to check an active cells value and came up with the following:
Sub CheckActive() If ActiveCell >= "1000" Then ActiveCell.Offset(0, -2).Value = "Higher than / Equal to 1000" ElseIf ActiveCell >= "100" Then ActiveCell.Offset(0, -2).Value = "Higher than / Equal to 100" ElseIf ActiveCell >= "10" Then ActiveCell.Offset(0, -2).Value = "Higher than / Equal to 10" Else ActiveCell.Offset(0, -2).Value = "Lower than 10" End If End Sub Problem is, that the first IF statement is found true everytime. I assume the problem lies in the definition of the IF statement, but being new to this, I am unsure. Any help, hints or pointers would be highly appreciated. _________________ Best regards, Steven Kristjansson [ This Message was edited by: SKR on 2002-05-26 07:56 ] |
|
|
|
|
|
#2 |
|
New Member
Join Date: May 2002
Location: Copenhagen, Denmark
Posts: 2
|
Got the previous to work with setting it up like this instead:
Sub CheckActive() If ActiveCell.Value >= 1000 Then ActiveCell.Offset(0, -2).Value = "Higher than / Equal to 1000" ElseIf ActiveCell.Value >= 100 Then ActiveCell.Offset(0, -2).Value = "Higher than / Equal to 100" ElseIf ActiveCell.Value >= 10 Then ActiveCell.Offset(0, -2).Value = "Higher than / Equal to 10" Else ActiveCell.Offset(0, -2).Value = "Lower than 10" End If End Sub |
|
|
|
|
|
#3 |
|
Board Regular
Join Date: Mar 2002
Location: Cincinnati, Ohio, USA
Posts: 6,824
|
An alternative to multiple If statements is a more readable Select Case...
Tom |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|