Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB in Excel 1

Status
Not open for further replies.

gxd135

MIS
Jun 18, 2001
41
US
Hello all,
I have recorded a couple of macros in excel to do various things. What I now want to do is run 1, 2, 3 or all of them if a certain cell value is greater than a certain number. What i have is a value in cell c5. If this value is greater than 5 I want to run the first macro. If the value is greater than 10 I want to run the second macro, and if the value is greater than 15 I want to run the third, and so on and so on. I am a beginner at writing VB code, but I know that this is pretty simple, I just don't know exactly what to do.

Any help would be greatly appreciated.

G
 
Look!

if the Value is 20...

is Value greater than 5? YES!!!
is Value greather than 10? YES, YES!!!
is Value greater than 15? YES, YES, YES!!! Skip,
metzgsk@voughtaircraft.com
 
Therefore will this run all three if the value is 20

Case Is > 5
Macro1
Case Is > 10
Macro2
Case Is > 15
Macro3
 
No, the Select Case will NOT work. Use...

if value > 5 then macro1
if value > 10 then macro2
if value > 15 then macro3
Skip,
metzgsk@voughtaircraft.com
 
OK,

This is all my code, Whats wrong?

Private Sub CommandButton1_Click()
Sheets("Route Sheet").Select
With Cells(5, 3)
If .Row <> 5 Then Exit Sub
If .Column <> 3 Then Exit Sub

If Value > 4 Then First_Copy
If Value > 9 Then Second_Copy
If Value > 14 Then Third_Copy


End With
End Sub
 
dot value...
Code:
 If .Value > 4 Then First_Copy

since we are doing
Code:
With Cells(5, 3)
The long way to reference each If would be..
Code:
If Cells(5,3).Value > 4 Then First_Copy
But using With, increased the eficiency of execution and the readability for maintenance.

:) Skip,
metzgsk@voughtaircraft.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top