Macro to Delete Rows Where Column a Is Blank
VBA to delete rows if cell is blank
- Qualityguy2
- Wander is marked as Solved.
-
- #1
Hello
I am struggling to edit unloaded rows. Here is my situation:
I have data in rows observed by the user. Data begins in row 10 and can draw near to row 55 if requisite. In row 56 I have formulas to sum the information in columns, and row 57 is for comments. Well-nig of the time users only when use 10-20 rows for information. BUT, they are lazy and I give the sack non get them to delete blank rows. So I am in need of any help with the VBA code to detect if the "r" run-in column 2 is blank shell, then delete the row, and shift rows up. I am victimisation a for-close loop with r as my replication, beginning at row 10, and going to last words (as plant by xcel ) minus 2 (the totals and comments). when gushing, i check and information technology loops done each wrangle, and identifies sort out start row 10, last row, 57, and mlr (go row of data) row 55.
BUT--- it deletes rows and leaves roughly 20 blank rows, and deletes my comments and totals rows?
Any thoughts, please?
my loop cipher is below :
- ' Instal loop to run to begin all information on totally rows on shipping write up
- For r = fr To mlr ' loops from first words of datd (rowing 10) to last row of data
- If Sheets("Report").Cells(r, 2).Apprais <> "" Then ' test for blank lines at end of news report
- ' ****** process the data and make pallet tags *****
- ' Clears out Atomic number 78 of data for next PT data
- Sheets("PT").Cells(2, 1) = ""
- Sheets("PT").Cells(4, 1) = ""
- Sheets("PT").Cells(4, 2) = ""
- Sheets("PT").Cells(6, 1) = ""
- Sheets("PT").Cells(8, 1) = ""
- Sheets("PT").Cells(11, 1) = ""
- Sheets("PT").Cells(13, 1) = ""
- Sheets("PT").Cells(15, 1) = ""
- Sheets("PT").Cells(15, 2) = ""
- Sheets("PT").Cells(20, 1) = ""
- Sheets("PT").Cells(17, 1) = ""
- Sheets("Atomic number 78").Cells(17, 2) = ""
- ' gets data from shipping report and puts on pallet tag
- Sheets("PT").Cells(2, 1).Value = Sheets("Report").Cells(2, 2).Value ' gets appointment
- ' If partial Case exists
- If Sheets("Report").Cells(r, 9).Prize = "Y" OR Sheets("Report").Cells(r, 9).Value = "y" Then ' if unfair shell exists
- If Sheets("Report").Cells(r, 5).Value = "N/A" Or Sheets("Report").Cells(r, 5).Time value = "-" Then ' allows user to input NA or -
- ml = 1
- Else
- cc = Sheets("Report").Cells(r, 5).Value ' get number of cases
- cc = cc - 1 ' minus 1 for the partial
- End If
- quant = Sheets("Composition").Cells(r, 6).Value ' to get total act of cartesian product on pallet
- part = Sheets("Paper").Cells(r, 10).Value ' to get under one's skin the incomplete amount of production
- pc = (quant - start out) / cc ' determine number in each full case
- Sheets("PT").Rows(4).ShrinkToFit = True
- Sheets("PT").Cells(4, 1).Value = "[email protected]" & Sheets("Report").Cells(r, 10).Value & " ; " &A; cc & "@" & PC ' fills just in case quanties
- Else
- If Sheets("Report").Cells(r, 5).Value = "N/A" Or Sheets("Reputation").Cells(r, 5).Apprais = "-" So ' allows user to input NA or -
- cc = 1
- Else
- cc = Sheets("Report").Cells(r, 5).Time value ' engender number of cases
- End If
- quant = Sheets("Cover").Cells(r, 6).Respect ' to get total number of product along pallet
- fc = quant / cc ' Determine numerate in each full example
- Sheets("PT").Cells(4, 1).Value = cardinal & " @ " & fc
- Goal If
- Sheets("PT").Cells(4, 2).Value = Sheets("Report").Cells(r, 6).Value ' Amount
- Sheets("PT").Rows(6).ShrinkToFit = Even ' set row 6 persona # to fit all
- Sheets("PT").Cells(6, 1).Value = Sheets("Report").Cells(r, 2).Value 'Part Number
- Sheets("PT").Rows(8).ShrinkToFit = Reliable ' determined row 8 Descrition to fit all
- Sheets("Atomic number 78").Cells(8, 1).Value = Sheets("Report").Cells(r, 1).Value ' description
- Sheets("Pt").Rows(11).ShrinkToFit = True ' set words 11 Lot # to match entirely
- ' to catch if lot # or PO are scare off sooner than n/a or entry
- If Sheets("Write up").Cells(r, 8).Value = "-" And then
- Sheets("PT").Cells(11, 1).Value = "N/A"
- Else
- Sheets("Pt").Cells(11, 1).Value = Sheets("Report").Cells(r, 8).Value ' Lot number
- End If
- Sheets("Pt").Rows(13).ShrinkToFit = On-key ' set row 13 Buy out Nobelium to outfit every last
- If Sheets("Theme").Cells(r, 7).Value = "-" Then
- Sheets("Platinum").Cells(13, 1).Value = "N/A"
- Else
- Sheets("Atomic number 78").Cells(13, 1).Value = Sheets("Report").Cells(r, 7).Treasure ' United States Post Office number
- End If
- Sheets("PT").Rows(15).ShrinkToFit = True ' set row 15 Palette # and Customer to suited all
- Sheets("Platinum").Cells(15, 1).Value = Sheets("Report").Cells(r, 4).Note value ' Pallet Number
- Sheets("PT").Cells(15, 2).Value = Sheets("Written report").Cells(2, 7).Value ' Vendor - customer
- Sheets("Atomic number 78").Cells(17, 1).Value = Sheets("Report").Cells(3, 2).Value ' counted / received by
- ' forms the pallet tag number
- Sheets("Platinum").Cells(20, 1) = molybdenum & yr & pn & seq ' puts the topical palette tag number on pallet label
- Sheets("Paper").Cells(r, 3).Value = atomic number 42 & year & pn & seq ' puts current pallet tag number on shipping report
- ' moves to next pallet tag along number for pallet number and chronological sequence
- pnI = pnI + 1
- pn = pnI
- pn = Right("00" & pn, 2) ' formats it to 2 digits
- seqI = seqI + 1
- seq = seqI
- seq = Right("0000" & seq, 4) ' formats it to 4 fingerbreadth
- ' to print out pallet tags 2 copies
- Sheets("PT").Activate
- Sheets("PT").Cells(22, 1).Value = "OFFICE"
- ActiveSheet.PrintOut Copies:=1
- Sheets("PT").Range("A22").Typeface.Bold = Sure
- Sheets("Platinum").Range("A22").Font.Italic = True
- Sheets("PT").Range("A22").Font.Name = "Times New Roman"
- Sheets("Platinum").Cells(22, 1).Value = "PRODUCT"
- ActiveSheet.PrintOut Copies:=1
- Sheets("Platinum").Stray("A22").Font.Bold = False
- Sheets("Atomic number 78").Range("A22").Font.Font = False
- Sheets("PT").Range("A22").Font.Name = "Arial"
- Else ' There is a blank row is no information
- MsgBox "fr= " &ere; fr & "mlr=b" & mlr & "lawrencium= " & lr &adenylic acid; "delete row " & r
- Sheets("Report").Cells(r, 1).EntireRow.Blue-pencil shift:=xlUp ' Remove blank dustup to continue to unconscious process
- Conclusion If
- Next r ' repeats loop-the-loop til last row of data
Show More
-
- #2
Re: VBA to cancel rows if cell is lacuna
To trial run for a blank cell and delete it, you must melt your loop from the last run-in to the first row. ie. Reverse order. An example is as follows which looks in Column B for blanks
- Dim lr as yearlong
- lr = range("B" & rows.numeration).end(xlup).quarrel
- Dim i as long-dated
- For i = Lr to 2 step -1 'loops from last row to row 2
- If range("B" & i) = "" then roll("B" &A; i).entirerow.delete
- Next i
Amend your code to do a vacat loop for that section of your codification.
-
- #3
Re: VBA to delete rows if cell is blank
Alan
Thanks for the cypher and the info. As a novice, i am always grasping for answsers. So, why does excel for you to work prepared from behind?
I would cogitate that for clean and efficient code, I could test the cellular phone As I am looping through with my process, and if it is blank, delete the wrangle.
Is this the reason?
if information is present in row 10, 11,12;
the first row deleted would be 13, and so row 14 becomes 13 - and since the loop has incremented it now is looking at row 14, only leaving the "new" row 13 .Is this correct?
-
- #4
Re: VBA to delete rows if cell is empty
- [COLOR=#333333]the first row deleted would live 13, then row 14 becomes 13 - and since the loop has incremented information technology today is looking at quarrel 14, only leaving the "new" row 13 . [/COLOR]
Your analysis skills are happening target.:)
-
- #5
Rhenium: VBA to delete rows if cell is blank
In that location is no need to loop topology to delete rows.
Remove the "Else" bit of your If statement and then use this after the For.......Next intertwine
- With Sheets("Report")
- Dim lRow As Long
- lRow = .Cells(.Rows.Count, 2).End(xlUp).Dustup
- .Cells(2, 2).Resize(lRow -1).SpecialCells(4).EntireRow.Delete
- End With
The end of your cypher should look the like this
- Sheets("PT").Cells(22, 1).Note value = "Cartesian product"
- ActiveSheet.PrintOut Copies:=1
- Sheets("PT").Range("A22").Font.Bold = False
- Sheets("Platinum").Range("A22").Font.Italic = False
- Sheets("PT").Range("A22").Font.Name = "Arial"
- End If
- Close r ' repeats loop til last row of data
- With Sheets("Write up")
- Dim lRow As Long
- lRow = .Cells(.Rows.Counting, 2).End(xlUp).Row
- .Cells(2, 2).Resize(lRow -1).SpecialCells(4).EntireRow.Delete
- Destruction With
Display More
SpecialCells(4) means cells that are devoid, so this codification deletes all rows where column B is blank in one become.
Macro to Delete Rows Where Column a Is Blank
Source: https://www.ozgrid.com/forum/index.php?thread%2F149636-vba-to-delete-rows-if-cell-is-blank%2F
0 Response to "Macro to Delete Rows Where Column a Is Blank"
Post a Comment