Macro to Delete Blank Rows in Multiple Sheets, Not Whole Workbook

jenmwentworth

New Member
Joined
Mar 1, 2022
Messages
5
Office Version
  1. 365
Platform
  1. Windows
I have been working on this macro for what seems like forever and I just can't get it to work.



I have a data set and when employees are terminated their names are removed from the spreadsheet and I need any monthly sales data to also be deleted. Employee names all "feed" from a main "Personal" sheet and this is where names are added and removed. When they are removed from the "Personal" tab, there is still a formula referring to the personal tab so there is actually "" data column A of the line.



There are 12 different sheets that I need the macro to run on all at once to delete the "blank" line(s) for any terminated employees. This is what I have so far. All this does is delete the blank line on the "Personal Entry" tab for the code is located. Also, I really don't want it limited to the range A3:A11, i was just testing that to see if it would work. I would like it to be column A, but my header is in both rows 1 & 2.



I am very new to VBA so please help.



Sub DeleteBlankRows()

'Delete Blank Rows For Terminated Employees

'Turn off Screen Updating
Application.ScreenUpdating = False

' Defines variable
Dim ws As Worksheet
Dim lastRow As Long 'This is the last row so code knows where to start

' Defines variable nSheets as the sheets you want to ignore
nSheets = Array("Bogey", "Data Imported", "Personal Entry")

'Defines variable lastRow as last row of Column A
lastRow = Cells(Rows.Count, 1).End(xlUp).Row

' For each sheet in the active workbook
For Each ws In ActiveWorkbook.Worksheets

' If the sheet name is not in the list nSheets then...
If Not IsNumeric(Application.Match(ws.Name, nSheets, 0)) Then

'Deletes Rows where Column A is empty
On Error Resume Next
With Range("A3:A11")
.Value = .Value
.SpecialCells(xlCellTypeBlanks).EntireRow.Delete
End With
End If

' Check next sheet
Next ws

'Turn on Screen Updating
Application.ScreenUpdating = True

End Sub

Commission Worksheet-Kitchen-sort testing recovered 3.xlsm
ABCDEFGHIKLMNOPQRSTUVWX
1SalespersonTotal February Net Sales $$ (Reported Sales + Sales Adjustments)Sales AdjustmentsReported February SalesGross Margin %%Net Margin %%Commission $$'s (Total Sales * Rate)Bonus markers (Total Sales Lookup)Commission Bonus $$ (Total Sales Lookup)Wk 1Wk 2Wk 3Wk 4Wk 5OT ADJ.Total Monthly Commission $$Total YTD Sales $$
2TotalOTTotalOTTotalOTTotalOTTotalOT
3BH - Bridgette$0.00$0.000$ -$ -$0.00$0.00
4MM - Melanie$0.00$0.000$ -$ -$0.00$0.00
5$0.00$0.000$ -$ -$0.00#N/A
6SLB - Seana$0.00$0.000$ -$ -$0.00$0.00
7CNR - Crystal$0.00$0.000$ -$ -$0.00$0.00
8TRACI - Traci$0.00$0.00#N/A#N/A$ -#N/A#N/A
9$0.00$0.000$ -$ -$0.00#N/A
10
11
February
Cell Formulas
RangeFormula
G3:G9G3=IFERROR(IF((VLOOKUP(A3,January,2,FALSE)>VLOOKUP(A3,Personal,4,FALSE)),(B3*(VLOOKUP(A3,Personal,3,FALSE))),IF(VLOOKUP(A3,FebYTD,2,FALSE)>VLOOKUP(A3,Personal,4,FALSE),((VLOOKUP(A3,FebYTD,2,FALSE)-VLOOKUP(A3,Personal,4,FALSE))*VLOOKUP(A3,Personal,3,FALSE))+((VLOOKUP(A3,Personal,4,FALSE)-VLOOKUP(A3,January,2,FALSE))*VLOOKUP(A3,Personal,2)),B3*VLOOKUP(A3,Personal,2,FALSE))),0)
H3:H9H3=IF(A3="",0,VLOOKUP(VLOOKUP(A3,FebYTD,2,FALSE),Bogey,3)-(VLOOKUP(A3,January,8,FALSE)))
I3:I9I3=IF(A3="",0,VLOOKUP(VLOOKUP(A3,FebYTD,2,FALSE),Bogey,6)-VLOOKUP(A3,January,9,FALSE))
U3:U9U3=IFERROR((((J3/K3)/2)*L3)+(((J3/M3)/2)*N3)+(((J3/O3)/2)*P3)+(((J3/Q3)/2)*R3)+(((J3/S3)/2)*T3),0)
V3:V9V3=G3+I3+U3
W3:W9W3=VLOOKUP(A3,FebYTD,2,FALSE)
B3:B9B3=+D3+C3
Named Ranges
NameRefers ToCells
Bogey=Bogey!$B$2:$G$28H3:I9
February=OFFSET(February!$A$3,0,0,COUNTA(February!$A:$A)-1,23)W3, G3:I3
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Change this:
VBA Code:
With Range("A3:A11")
to this:
VBA Code:
With ws.Range("A3:A" & lastRow)
 
Upvote 0
Solution
Change this:
VBA Code:
With Range("A3:A11")
to this:
VBA Code:
With ws.Range("A3:A" & lastRow)
Thank You, that will fix my "range" issue, but it still won't execute this on all the sheets I want it to in my workbook.
 
Upvote 0
Here is where your macro already identifies your sheets, all others will be processed (change entries as needed):
VBA Code:
' Defines variable nSheets as the sheets you want to ignore
nSheets = Array("Bogey", "Data Imported", "Personal Entry")
 
Upvote 0
Here is where your macro already identifies your sheets, all others will be processed (change entries as needed):
VBA Code:
' Defines variable nSheets as the sheets you want to ignore
nSheets = Array("Bogey", "Data Imported", "Personal Entry")
Thank you so much, it is working now.
 
Upvote 0

Forum statistics

Threads
1,214,593
Messages
6,120,435
Members
448,961
Latest member
nzskater

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