VBA, If Cells Blank End Sub

MrMaker

Board Regular
Joined
Jun 7, 2018
Messages
56
Office Version
  1. 365
Platform
  1. Windows
Hello everyone,

A simple one no doubt........I have inherited the below code and would like to amend to include a statement at the beginning to echo the following: IF CELL Z1 ON SHEET 6 IS BLANK THEN END SUB, OTHERWISE DO ALL THE BELOW.

Can anyone advise please?

Thanks very much in advance

VBA Code:
Private Sub Workbook_Open()
Dim Ws As Worksheet
Dim Crit As String
Application.ScreenUpdating = False
Crit = Sheets("SHEET1").Range("A1").Value
For Each Ws In Worksheets
Select Case Ws.Name
Case "SHEET2", "SHEET3"
Ws.UsedRange.AutoFilter 1, "<>" & Crit
Ws.AutoFilter.Range.Offset(1).EntireRow.Delete
Ws.AutoFilterMode = False
Ws.Range("A2:A" & Ws.Rows.Count).RowHeight = 25
Ws.Activate
Ws.Cells.Copy
Ws.Range("A1").PasteSpecial Paste:=xlValues
Ws.Range("A1").Select
Application.CutCopyMode = False
End Select
Select Case Ws.Name
Case "SHEET4"
Ws.Range("A1").Select
End Select
Next Ws
With Sheets("SHEET1")
.Range("A1").Value = Crit
.Rows.RowHeight = 36
.Visible = xlVeryHidden
Worksheets("Summary").Activate
ThisWorkbook.Protect Password:="123", Structure:=True, Windows:=True
End With
End Sub
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Verify that the sheet name is correct "SHEET6".
Add the following line to the macro, it is highlighted in blue.

Rich (BB code):
Private Sub Workbook_Open()
Dim Ws As Worksheet
Dim Crit As String
Application.ScreenUpdating = False

If Sheets("SHEET6").Range("Z1").Value = "" Then Exit Sub

Crit = Sheets("SHEET1").Range("A1").Value
For Each Ws In Worksheets
Select Case Ws.Name
Case "SHEET2", "SHEET3"
Ws.UsedRange.AutoFilter 1, "<>" & Crit
Ws.AutoFilter.Range.Offset(1).EntireRow.Delete
Ws.AutoFilterMode = False
Ws.Range("A2:A" & Ws.Rows.Count).RowHeight = 25
Ws.Activate
Ws.Cells.Copy
Ws.Range("A1").PasteSpecial Paste:=xlValues
Ws.Range("A1").Select
Application.CutCopyMode = False
End Select
Select Case Ws.Name
Case "SHEET4"
Ws.Range("A1").Select
End Select
Next Ws
With Sheets("SHEET1")
.Range("A1").Value = Crit
.Rows.RowHeight = 36
.Visible = xlVeryHidden
Worksheets("Summary").Activate
ThisWorkbook.Protect Password:="123", Structure:=True, Windows:=True
End With
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,224,820
Messages
6,181,160
Members
453,021
Latest member
Justyna P

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