Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Macro to remove rows

I need a macro that will delete all rows that don't have an "account number"
in a certain column. The spreadsheet has been imported from a text format
and I need to delete the rows that include the page headers, column headings
etc.

Thanks.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Macro to remove rows


You will get the response you need if you give us more to go on!, which
column? which header names? do the header names appear legitimately on
the sheet? if so where?....etc


--
The Code Cage Team

Regards,
The Code Cage Team
http://www.thecodecage.com
------------------------------------------------------------------------
The Code Cage Team's Profile: http://www.thecodecage.com/forumz/member.php?userid=2
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=31737

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Macro to remove rows

Try something like the following:

Sub DeleteThem()
Const TEST_COL = "B" '<<< Change to appropriate column
Const DATA_COL = "C" '<<< Change to appropriate column
Const TOP_ROW = 2 '<<< Change to first row with data
Const SHEET_NAME = "Sheet2" '<<< Change to sheet name
Dim RowNdx As Long
Dim LastRow As Long
Dim WS As Worksheet

Set WS = ThisWorkbook.Worksheets(SHEET_NAME)
With WS
LastRow = .Cells(.Rows.Count, TEST_COL).End(xlUp).Row
If LastRow < TOP_ROW Then
Exit Sub
End If
For RowNdx = LastRow To TOP_ROW Step -1
If .Cells(RowNdx, DATA_COL).Value = vbNullString Then
.Rows(RowNdx).Delete
End If
Next RowNdx
End With
End Sub


Change TEST_COL to the column letter that is used to find the last row
of data. The deletion process will start at the last non-blank row in
this column. Change DATA_COL to the column letter that contains your
account numbers. This can be, but need not be, the same as TEST_COL.
Change TOP_ROW to the row number of the first row in the worksheet
that contains data subject to deletion. If your worksheet contains
heading rows, set TOP_ROW to the row below your heading section. No
rows above TOP_ROW will be deleted, regardless of their content.
Change SHEET_NAME to the name of the worksheet containing the data.

Then, just run the code.

Cordially,
Chip Pearson
Microsoft MVP
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)





On Wed, 19 Nov 2008 13:05:00 -0800, Kueck
wrote:

I need a macro that will delete all rows that don't have an "account number"
in a certain column. The spreadsheet has been imported from a text format
and I need to delete the rows that include the page headers, column headings
etc.

Thanks.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Macro to remove rows


Chip, without more to go on we can't give a full answer as the OP has
said that headers appear in the rows too which he would like deleting, i
guess he would be better off hard coding an array of those headers
although he doesn't specify if they are found only in one column or
anywhere in the range, which makes it very difficult to imagine his
scenario.


--
The Code Cage Team

Regards,
The Code Cage Team
'The Code Cage' (http://www.thecodecage.com)
------------------------------------------------------------------------
The Code Cage Team's Profile: http://www.thecodecage.com/forumz/member.php?userid=2
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=31737

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
Macro to Automatically remove blank rows Jack Wood Excel Discussion (Misc queries) 4 May 26th 09 08:43 PM
"Add/Remove Rows Code" adds rows on grouped sheets, but won't remove rows. Conan Kelly Excel Programming 1 November 16th 07 10:41 PM
Need macro to remove blank rows Bob Excel Programming 7 June 21st 06 01:21 PM
Need macro to remove duplicate rows in a wksht with same order# G2 in AUS Excel Discussion (Misc queries) 2 December 16th 05 05:44 PM
Macro to remove empty rows Tammy[_3_] Excel Programming 4 August 5th 04 01:10 PM


All times are GMT +1. The time now is 07:35 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"