If,Then,Else Macro

G

Guest

Dear Experts
I have an Auto_Open Macro using the If, Then, Else statement for each time I
open the spreadsheet it gives me the msgbox of percent completed. Here is
what I have so far and it works with one problem. If Range ("Schedule!L1") =0
or is blank I get the Debug window upon opening the spreadsheet. How do I
write this macro to tell Auto_open to ignore L1 cell if it is less then 0, or
= to 0 or is blank?
Cell L1 is formatted for percentage.
Sub Auto_Open()
Dim Value1 As Integer
Dim Value2 As Integer
If Range("Schedule!L1") > 0 Then
Value1 = Worksheets("Schedule").Range("L1") * 100
Value2 = Worksheets("Schedule").Range("M1") * 100
MsgBox "YOUR JOB IS " & (Value1) & " % " & "DETAILED" & " AND " & (Value2) &
" % " & "SHIPPED", vbInformation, "PERCENT COMPLETE"
End If
End Sub
 
M

Mike Fogleman

Sub Auto_Open()
Dim Value1 As Integer
Dim Value2 As Integer
If Range("Schedule!L1") > 0 Then
Value1 = Worksheets("Schedule").Range("L1") * 100
Value2 = Worksheets("Schedule").Range("M1") * 100
MsgBox "YOUR JOB IS " & (Value1) & " % " & "DETAILED" & " AND " & (Value2) &
" % " & "SHIPPED", vbInformation, "PERCENT COMPLETE"
Else
Exit Sub (or some other values and/or message)
End If
End Sub

Mike F
 
D

Dave D-C

He4Giv said:
.. How do I .. ignore L1 cell ..
Sub Auto_Open()
Dim Value1 As Integer
Dim Value2 As Integer
If Range("Schedule!L1") > 0 Then
Value1 = Worksheets("Schedule").Range("L1") * 100
Value2 = Worksheets("Schedule").Range("M1") * 100
MsgBox "YOUR JOB IS " & (Value1) & " % " & "DETAILED" & " AND " & (Value2) &
" % " & "SHIPPED", vbInformation, "PERCENT COMPLETE"
End If
End Sub

I think you want
If IsNumeric(Range("Schedule!A1")) Then
If Range("Schedule!A1") > 0 Then
' ..
End If
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top