Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Iteratively delete rows from a spreadsheet

I have a very large spreadsheet (about 50,000 rows, and to CM of
columns) with blocks of data 20 rows high (rows 1-20 are from Building
A, rows 21-40 are from Building B, etc). However, not every row in
each block of 20 has information in it - some are just placeholders.
For example, some blocks may have rows 1-18 filled with data while
other blocks may have only 1-6 filled with data.

I am interested in programming a macro that would delete the
placeholder rows out of the spreadsheet based on a certain criteria.
This would probably halve the size of my spreadsheet.

In faux-code:

For row i
i = 1 to 50,000
If Column B = #NA
Delete row i


Is this something that can be done with a macro, or do I need to go
through all of these rows by hand? Obviously, I haven't programmed
macros before (I've taken code and run it), but I've programmed in
other languages (Java, C#). Could someone point me in the right
direction?

Thanks,

V. Hagberg
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,565
Default Iteratively delete rows from a spreadsheet

If you no longer want to maintain the 20 row grouping per building, then it
is better to work from the bottom up when deleteing rows. This will avoid
the inadvertant skipping of consecutive rows that meet the delete criteria
because of the default shift up.

Sub delRw()
Dim lr As Long
lr = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
For i = lr To 2
If Cells(i, 2) = #NA Then
Row(i).Delete
End If
Next
End Sub


"Vicki Hagberg" wrote in message
...
I have a very large spreadsheet (about 50,000 rows, and to CM of
columns) with blocks of data 20 rows high (rows 1-20 are from Building
A, rows 21-40 are from Building B, etc). However, not every row in
each block of 20 has information in it - some are just placeholders.
For example, some blocks may have rows 1-18 filled with data while
other blocks may have only 1-6 filled with data.

I am interested in programming a macro that would delete the
placeholder rows out of the spreadsheet based on a certain criteria.
This would probably halve the size of my spreadsheet.

In faux-code:

For row i
i = 1 to 50,000
If Column B = #NA
Delete row i


Is this something that can be done with a macro, or do I need to go
through all of these rows by hand? Obviously, I haven't programmed
macros before (I've taken code and run it), but I've programmed in
other languages (Java, C#). Could someone point me in the right
direction?

Thanks,

V. Hagberg



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,565
Default Iteratively delete rows from a spreadsheet

Had a senior moment there.

Change the line:

For i = lr To 2

To:

For i = lr To 2 Step -1



"Vicki Hagberg" wrote in message
...
I have a very large spreadsheet (about 50,000 rows, and to CM of
columns) with blocks of data 20 rows high (rows 1-20 are from Building
A, rows 21-40 are from Building B, etc). However, not every row in
each block of 20 has information in it - some are just placeholders.
For example, some blocks may have rows 1-18 filled with data while
other blocks may have only 1-6 filled with data.

I am interested in programming a macro that would delete the
placeholder rows out of the spreadsheet based on a certain criteria.
This would probably halve the size of my spreadsheet.

In faux-code:

For row i
i = 1 to 50,000
If Column B = #NA
Delete row i


Is this something that can be done with a macro, or do I need to go
through all of these rows by hand? Obviously, I haven't programmed
macros before (I've taken code and run it), but I've programmed in
other languages (Java, C#). Could someone point me in the right
direction?

Thanks,

V. Hagberg



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Iteratively delete rows from a spreadsheet

Option Explicit
Sub Testme01()

Dim iRow as long
Dim LastRow as long
dim FirstRow as long
with worksheets("Somesheetnamehere")
FirstRow = 1
lastrow = .cells(.rows.count,"B").end(xlup).row
for irow = lastrow to firstrow step -1
if iserror(.cells(irow,"B").value) then
.rows(irow).delete
end if
next irow
end with

End Sub

This actually tested for any error in column B.

You may want to use:
if lcase(.cells(irow,"B").text) = lcase("#N/A") then

for just #n/a's.



Vicki Hagberg wrote:

I have a very large spreadsheet (about 50,000 rows, and to CM of
columns) with blocks of data 20 rows high (rows 1-20 are from Building
A, rows 21-40 are from Building B, etc). However, not every row in
each block of 20 has information in it - some are just placeholders.
For example, some blocks may have rows 1-18 filled with data while
other blocks may have only 1-6 filled with data.

I am interested in programming a macro that would delete the
placeholder rows out of the spreadsheet based on a certain criteria.
This would probably halve the size of my spreadsheet.

In faux-code:

For row i
i = 1 to 50,000
If Column B = #NA
Delete row i

Is this something that can be done with a macro, or do I need to go
through all of these rows by hand? Obviously, I haven't programmed
macros before (I've taken code and run it), but I've programmed in
other languages (Java, C#). Could someone point me in the right
direction?

Thanks,

V. Hagberg


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Fast Way to Delete Rows from Big Spreadsheet (Using VBA) LarryP Excel Programming 5 May 21st 08 02:44 PM
How do i delete empty rows in a spreadsheet Jim Excel Discussion (Misc queries) 2 July 19th 07 11:03 PM
Macro to delete certain rows in a spreadsheet Gary Excel Programming 2 June 11th 07 05:03 PM
Macro/VBA to delete rows in Spreadsheet Colin Foster[_5_] Excel Programming 5 June 17th 06 12:47 PM
delete all blank rows in a spreadsheet Richard Excel Programming 25 May 27th 06 07:47 AM


All times are GMT +1. The time now is 05:06 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"