Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 45
Default VB Code to Delete Unused Rows

Excel 2000 ... No response to an earlier post, but turns
out I didn't have issue correct either.

I have a Template consisting of 15003 rows ... The last
row which might contain data is 15000 ... with row 15001
being empty ... & 15002 & 15003 containing various totals.

I copy/paste in a random amount of data (2000-11000
records & then run a recorded Macro to format data.

Issue is ... I would like VB Code to place near end of
Macro that would delete all unused rows between end of
data & row 15000 (while keeping rows 15001, 15002 & 15003).

The following VB Code worked fine until I added the Totals
to rows 15002 & 15003 ... These rows now get deleted (so
goes the Totals) ... I wish to keep them.

cLastRow = Cells(Rows.Count, "B").End(xlUp).Row
Set myRng = Range("B" & cLastRow + 1 & ":B15000")
myRng.EntireRow.Delete

Note: Col A is Blank ... Col B contains data

Above said ... can one of you many Wizards of this board
tell me what adjustments to above code I must make ...
or ... offer me new code all together to handle this???

My many thanks to those of you that support these
boards ... Kha
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default VB Code to Delete Unused Rows

cLastRow = Cells(15001, "B").End(xlUp).Row
Set myRng = Range("B" & cLastRow + 1 & ":B15000")
myRng.EntireRow.Delete


--
Regards,
Tom Ogilvy

"Ken" wrote in message
...
Excel 2000 ... No response to an earlier post, but turns
out I didn't have issue correct either.

I have a Template consisting of 15003 rows ... The last
row which might contain data is 15000 ... with row 15001
being empty ... & 15002 & 15003 containing various totals.

I copy/paste in a random amount of data (2000-11000
records & then run a recorded Macro to format data.

Issue is ... I would like VB Code to place near end of
Macro that would delete all unused rows between end of
data & row 15000 (while keeping rows 15001, 15002 & 15003).

The following VB Code worked fine until I added the Totals
to rows 15002 & 15003 ... These rows now get deleted (so
goes the Totals) ... I wish to keep them.

cLastRow = Cells(Rows.Count, "B").End(xlUp).Row
Set myRng = Range("B" & cLastRow + 1 & ":B15000")
myRng.EntireRow.Delete

Note: Col A is Blank ... Col B contains data

Above said ... can one of you many Wizards of this board
tell me what adjustments to above code I must make ...
or ... offer me new code all together to handle this???

My many thanks to those of you that support these
boards ... Kha



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VB Code to Delete Unused Rows

This code should work if all of the rows with data have something entered in
column A. If not, use a column that would have data in every row. If not the
first
worksheet, substitute sheet name for (1).


Dim x As Integer

x = 2000 'counter for rows beginning with row 2000

Sheets(1).Unprotect 'Include if sheet is protected

'Loops through rows. If cell in column A is blank, select row and delete
Do While x < 15001
If Sheets(1).Cells(x, 1).Value = "" Then
Cells(x, 1).Select
Selection.EntireRow.Delete
x = x + 1
Else
x = x + 1
End If

Loop

Sheets(1).Protect 'Use if you want sheet protected

"Ken" wrote:

Excel 2000 ... No response to an earlier post, but turns
out I didn't have issue correct either.

I have a Template consisting of 15003 rows ... The last
row which might contain data is 15000 ... with row 15001
being empty ... & 15002 & 15003 containing various totals.

I copy/paste in a random amount of data (2000-11000
records & then run a recorded Macro to format data.

Issue is ... I would like VB Code to place near end of
Macro that would delete all unused rows between end of
data & row 15000 (while keeping rows 15001, 15002 & 15003).

The following VB Code worked fine until I added the Totals
to rows 15002 & 15003 ... These rows now get deleted (so
goes the Totals) ... I wish to keep them.

cLastRow = Cells(Rows.Count, "B").End(xlUp).Row
Set myRng = Range("B" & cLastRow + 1 & ":B15000")
myRng.EntireRow.Delete

Note: Col A is Blank ... Col B contains data

Above said ... can one of you many Wizards of this board
tell me what adjustments to above code I must make ...
or ... offer me new code all together to handle this???

My many thanks to those of you that support these
boards ... Kha

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
How can i delete unused row and columns ??? Irfan Khan[_2_] Excel Discussion (Misc queries) 8 January 15th 08 07:26 PM
VBA code to delete rows Secret Squirrel Excel Discussion (Misc queries) 3 January 21st 07 03:01 PM
how to delete unused footer dialogs in excell Jaycee Excel Worksheet Functions 0 September 29th 05 08:07 PM
code to delete rows ianalexh Excel Discussion (Misc queries) 5 May 5th 05 10:46 AM
Code not going to next unused row goss[_30_] Excel Programming 2 August 9th 04 05:04 AM


All times are GMT +1. The time now is 03:02 PM.

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

About Us

"It's about Microsoft Excel"