|
-
Jul 17th, 2007, 03:50 AM
#1
Thread Starter
New Member
[Excel] Macro to delete
Hey
Im currently in the process of editing a huge spreadsheet, step by step, and its proving to be a huge task.
I was wondering if there is a macro out there, or if anyone can help with one, which will delete an entire row (not just remove its contents and leave it blank, delete the row and shift it up), if the cell on that row in column "G" is empty.
The idea basically would be the code would work through every line of the spreadsheet, deleting any rows with a blank cell in the "G" column.
so i guess it would include "Selection.Delete Shift:=xlUp" somewhere in the code...?
any help would be apreciated?
thanks
-
Jul 17th, 2007, 04:17 AM
#2
Re: [Excel] Macro to delete
Welcome to the Forums.
Yes, a macro recording will give you the starting point of how Excel would do part of it.
You will want to inclide a few routines like...
Get the row count so you are not going through the entire sheel.
Test for G? cell if its blank.
Delete the row if it is blank.
Code:
Dim i As Long
Dim lRowCount As Long
lRowCount = Workbooks(1).Sheets("Sheet1").Cells.SpecialCells(xlCellTypeLastCell).Row
For i = 1 To lRowCount
If Workbooks(1).Sheets("Sheet1").Cells(i, 7).Value = vbNullString Then
Workbooks(1).Sheets("Sheet1").Rows(i & ":" & i).Delete Shift:=xlUp
End If
Next
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jul 17th, 2007, 05:15 AM
#3
Thread Starter
New Member
Re: [Excel] Macro to delete
thanks for the quick reply, especially with how early in the morning it is over there
Ive put this into a macro, however it seems to give me
"run time error 9, subscript out of range" error, when i debug it highlights "lRowCount = Workbooks(1).Sheets("Sheet1").Cells.SpecialCells(xlCellTypeLastCell).Row" line
There are 7590 rows in the spreadsheet im editing
Im do know a bit of vb code, however this is in excel seems to be more confusing
any further advice?
thanks again
-
Jul 17th, 2007, 05:28 AM
#4
Thread Starter
New Member
Re: [Excel] Macro to delete
no matter, i figured it out, the sheet had been renamed, i just had to change the name
all sorted then, thanks =]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|