Cell Value >0 then Run Macro

pinkpanther6666

Board Regular
Joined
Feb 13, 2008
Messages
194
Office Version
  1. 365
Platform
  1. Windows
Im trying to run some VBA and getting a Compile error stating Else without If

My code is listed below
Cant seem for the life of me what is wrong ... probably staring me in the face



Range("C4").Select
If Range("C4").Value > 0 Then Range("B4:G4").Select
Call Macro1
Else End

All macro1 is a formatting macro with thick borders


Can anyone help


Many Thanks


Steve
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
There are two forms of if statements the one line and the multiline
The one line does not need and end if. Your code has the one line version
Code:
If Range("C4").Value > 0 Then Range("B4:G4").Select
Because of this your Else does not have a if statement with it.

the multi line version would be
Code:
If Range("C4").Value > 0 Then
[INDENT]Range("B4:G4").Select[/INDENT]
[INDENT]  Call Macro1[/INDENT]
else[INDENT]  code to run if false[/INDENT]
 
 End If
 
Upvote 0
pinkpanther6666,

We have not see all of your macro code?

When posting VBA code, please use Code Tags - like this:

[code=rich]

'Paste your code here.

[/code]



See if the following macro codes will help you to understand the logic?


Rich (BB code):
Sub test()

Range("C4").Select
If Range("C4").Value > 0 Then
  Range("B4:G4").Select
  Call Macro1
Else
  Exit Sub
End If

End Sub


Sub Macro1()

  'All macro1 is a formatting macro with thick borders?????

  Range("A1").Select
  
End Sub
 
Upvote 0
pinkpanther6666,

Thanks for the feedback.

You are very welcome. Glad we could help.

And, come back anytime.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,183
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top