Performing a macro if a condition is true in a specified cell

WenlockExcel

New Member
Joined
Aug 29, 2011
Messages
2
I already have a workin macro that performs the activity I want done - which is to some fields to specified values and to then clear values in a series of others. However, I now I want to add an If Then Else statement to macro that will only allow the macro to operate if a specified condition is true. So ---

Cell AG1 can equal "Go" or "No Go". and I want the macro to works as follows

IF SAG1 = "Go"
Then

Range("O2").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "0"
Range("M2").Select
ActiveCell.FormulaR1C1 = "0"
Range("C2").Select
ActiveCell.FormulaR1C1 = "0"
Selection.AutoFill Destination:=Range("C2:C716"), Type:=xlFillDefault
Range("C2:C716").Select
ActiveWindow.ScrollRow = 1
Range("D1").Select
Selection.ClearContents
End Sub

ElseIf AG1 = "No Go"

End Sub


Any advice on how I shoudl do this please?
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Try this in the worksheet your data is on
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address = "AG1" Then
Range("O2").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "0"
Range("M2").Select
ActiveCell.FormulaR1C1 = "0"
Range("C2").Select
ActiveCell.FormulaR1C1 = "0"
Selection.AutoFill Destination:=Range("C2:C716"), Type:=xlFillDefault
Range("C2:C716").Select
ActiveWindow.ScrollRow = 1
Range("D1").Select
Selection.ClearContents
End Sub
 
Upvote 0
Forgot the End IF

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address = "AG1" Then
 Range("O2").Select
 Application.CutCopyMode = False
 ActiveCell.FormulaR1C1 = "0"
 Range("M2").Select
 ActiveCell.FormulaR1C1 = "0"
 Range("C2").Select
 ActiveCell.FormulaR1C1 = "0"
 Selection.AutoFill Destination:=Range("C2:C716"), Type:=xlFillDefault
 Range("C2:C716").Select
 ActiveWindow.ScrollRow = 1
 Range("D1").Select
 Selection.ClearContents
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,286
Members
452,902
Latest member
Knuddeluff

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