VBA run macro if

L

Legacy 51064

Guest
On J4 of the summary sheet, there will be either a 1 or 0 depending on which macro has been executed. How can I add an If statement to see if the value in J4 is 0 or 1? I would like to be able to execute this macro only if the value in J4 is 0.

Thank you for all of your help.


Sub WeeklyReport()

'Used for last row number
Dim RowCount As Long
Dim ws As Worksheet

'Used for row number for week beginning date
Dim i As Integer

'Set first row number for beginning date
i = 4

'Select all of the Weekly Sheets and move the columns one column to the right
For Each ws In ActiveWorkbook.Worksheets
If ws.Name <> "Summary" Then
ws.Range("A1").EntireColumn.Insert
ws.Range("A1").Value = "WKBeg"
ws.Range("B1").Value = "Status"
ws.Range("C1").Value = "Message"
ws.Range("D1").Value = "Person Name"
ws.Range("E1").Value = "Elements"
ws.Range("F1").Value = "Project"
ws.Range("G1").Value = "Tasks"
ws.Range("H1").Value = "Sat"
ws.Range("I1").Value = "Sun"
ws.Range("J1").Value = "Mon"
ws.Range("K1").Value = "Tues"
ws.Range("L1").Value = "Wed"
ws.Range("M1").Value = "Thu"
ws.Range("N1").Value = "Fri"

'Get the last row number
RowCount = ws.Range("D1").End(xlDown).Row

'Add the Beginning date of the week
ws.Range("S2").Value = _
Sheets("Summary").Range("A" & i)
ws.Range("A2:A" & RowCount).Value = _
Sheets("Summary").Range("B" & i)
i = i + 1
End If

If ws.Name = "Summary" Then
ws.Range("F4").Value = "The dates ARE active"
ws.Range("J4").Value = "1"

'Message Box
MsgBox ("The weekly start date has been added.")

End If

Next ws

'Change the worksheet name to the appropriate name
For Each ws In ActiveWorkbook.Worksheets
If ws.[S2].Value > 0 Then
ws.Name = ws.[S2].Value
End If

Next ws

'Reposition back on Enter
Sheets("Summary").Select

End Sub
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Try this as the first line in your macro:

If Worksheets("Summary").Range("J4").Value = "1" Then Exit Sub
 
Upvote 0
Code:
Sub WeeklyReport() 

if sheets("summary sheet").range("j4") <> 0 then
   exit sub
end if

'your code

End Sub
 
Upvote 0

Forum statistics

Threads
1,203,025
Messages
6,053,103
Members
444,639
Latest member
xRockox

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