Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 112
Default Macro for Deleting Specific Rows?

Hello all,

I am seeking help regarding a new accounting system that imports info
into excel. When it imports, it leaves blank rows as well as rows
with "----------" in it. It also gives totals and subtotals under
certain categories.

I would like to delete the blank rows, delete the rows with the
"---------" as well as delete the rows that have the category totals.
Is there a macro out there where I could identify and delete rows with
these criteria? Any help would be greatly appreciated. Thank you for
your time in advance.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 119
Default Macro for Deleting Specific Rows?

There have been a large number of postings discussing deleteing rows. A
quick search of the group should yeild many examples. Always start at the
bottom of the sheet when deleting.

"cardan" wrote:

Hello all,

I am seeking help regarding a new accounting system that imports info
into excel. When it imports, it leaves blank rows as well as rows
with "----------" in it. It also gives totals and subtotals under
certain categories.

I would like to delete the blank rows, delete the rows with the
"---------" as well as delete the rows that have the category totals.
Is there a macro out there where I could identify and delete rows with
these criteria? Any help would be greatly appreciated. Thank you for
your time in advance.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,836
Default Macro for Deleting Specific Rows?

Sub delete_rows()

Dim RowNdx As Long
Dim LastRow As Long
LastRow = ActiveSheet.UsedRange.Rows.Count
Try this:

For RowNdx = LastRow To 1 Step -1
If Cells(RowNdx, "A").Value = "" Or Cells(RowNdx, "A").Value = "----------"
Or Cells(RowNdx, "A").Value = "total" Or Cells(RowNdx, "A").Value =
"subtotal" Then 'Change the "A" to another Column is needed
Rows(RowNdx).Delete
End If
Next RowNdx
End Sub

Regards,
Ryan---
--
RyGuy


"cardan" wrote:

Hello all,

I am seeking help regarding a new accounting system that imports info
into excel. When it imports, it leaves blank rows as well as rows
with "----------" in it. It also gives totals and subtotals under
certain categories.

I would like to delete the blank rows, delete the rows with the
"---------" as well as delete the rows that have the category totals.
Is there a macro out there where I could identify and delete rows with
these criteria? Any help would be greatly appreciated. Thank you for
your time in advance.


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 112
Default Macro for Deleting Specific Rows?

On Aug 14, 9:06 pm, ryguy7272
wrote:
Sub delete_rows()

Dim RowNdx As Long
Dim LastRow As Long
LastRow = ActiveSheet.UsedRange.Rows.Count
Try this:

For RowNdx = LastRow To 1 Step -1
If Cells(RowNdx, "A").Value = "" Or Cells(RowNdx, "A").Value = "----------"
Or Cells(RowNdx, "A").Value = "total" Or Cells(RowNdx, "A").Value =
"subtotal" Then 'Change the "A" to another Column is needed
Rows(RowNdx).Delete
End If
Next RowNdx
End Sub

Regards,
Ryan---
--
RyGuy



"cardan" wrote:
Hello all,


I am seeking help regarding a new accounting system that imports info
into excel. When it imports, it leaves blank rows as well as rows
with "----------" in it. It also gives totals and subtotals under
certain categories.


I would like to delete the blank rows, delete the rows with the
"---------" as well as delete the rows that have the category totals.
Is there a macro out there where I could identify and delete rows with
these criteria? Any help would be greatly appreciated. Thank you for
your time in advance.- Hide quoted text -


- Show quoted text -


RyGuy, Thank you for the response. The Macro works, for the most
part, however there are some issues on my end. I realized that when I
import the numbers from the accounting program, "blank" cells are
actually not blank. Even though there are no number or anything in
them, Excel still picks up something in them. When I highlight the row
in question and hit delete, then run the macro, it will only then read
the rows as blank and delete them. I tried changing your formula from
"" to 0 but that also does not work.

Also the rows with "totals" in them that I need to get rid of contain
the word total with the heading name as well. ie Total Finance, Total
Design, etc... Is there a way I can get rid of a row in a column
contains the word "Total"?

Thank you for your help. I am very appreciative!

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,836
Default Macro for Deleting Specific Rows?

Sorry, for the delayed follow-up; extremely busy these past several days.
Hope this does what you want (notice, I used Column B as a helper column;
your Column B must be empty...Click on B and shift right one Column).


Sub delete_rows()

Dim RowNdx As Long
Dim LastRow As Long
LastRow = ActiveSheet.UsedRange.Rows.Count

Range("B1").Select
ActiveCell.FormulaR1C1 = "=TRIM(RC[-1])"
Selection.AutoFill Destination:=Range("B1:B22") ' Change to suit your needs
Range("B1:B22").Select
Range("C1").Select

For RowNdx = LastRow To 1 Step -1
If Cells(RowNdx, "B").Value = "" Or Cells(RowNdx, "B").Value = "----------" _
Or Cells(RowNdx, "B").Value = "total" Or Cells(RowNdx, "B").Value = _
"subtotal" Then 'Change the "B" to another Column is needed
Rows(RowNdx).Delete
End If
Next RowNdx
End Sub


--
RyGuy


"cardan" wrote:

On Aug 14, 9:06 pm, ryguy7272
wrote:
Sub delete_rows()

Dim RowNdx As Long
Dim LastRow As Long
LastRow = ActiveSheet.UsedRange.Rows.Count
Try this:

For RowNdx = LastRow To 1 Step -1
If Cells(RowNdx, "A").Value = "" Or Cells(RowNdx, "A").Value = "----------"
Or Cells(RowNdx, "A").Value = "total" Or Cells(RowNdx, "A").Value =
"subtotal" Then 'Change the "A" to another Column is needed
Rows(RowNdx).Delete
End If
Next RowNdx
End Sub

Regards,
Ryan---
--
RyGuy



"cardan" wrote:
Hello all,


I am seeking help regarding a new accounting system that imports info
into excel. When it imports, it leaves blank rows as well as rows
with "----------" in it. It also gives totals and subtotals under
certain categories.


I would like to delete the blank rows, delete the rows with the
"---------" as well as delete the rows that have the category totals.
Is there a macro out there where I could identify and delete rows with
these criteria? Any help would be greatly appreciated. Thank you for
your time in advance.- Hide quoted text -


- Show quoted text -


RyGuy, Thank you for the response. The Macro works, for the most
part, however there are some issues on my end. I realized that when I
import the numbers from the accounting program, "blank" cells are
actually not blank. Even though there are no number or anything in
them, Excel still picks up something in them. When I highlight the row
in question and hit delete, then run the macro, it will only then read
the rows as blank and delete them. I tried changing your formula from
"" to 0 but that also does not work.

Also the rows with "totals" in them that I need to get rid of contain
the word total with the heading name as well. ie Total Finance, Total
Design, etc... Is there a way I can get rid of a row in a column
contains the word "Total"?

Thank you for your help. I am very appreciative!




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 112
Default Macro for Deleting Specific Rows?

On Aug 25, 7:22 am, ryguy7272
wrote:
Sorry, for the delayed follow-up; extremely busy these past several days.
Hope this does what you want (notice, I used Column B as a helper column;
your Column B must be empty...Click on B and shift right one Column).

Sub delete_rows()

Dim RowNdx As Long
Dim LastRow As Long
LastRow = ActiveSheet.UsedRange.Rows.Count

Range("B1").Select
ActiveCell.FormulaR1C1 = "=TRIM(RC[-1])"
Selection.AutoFill Destination:=Range("B1:B22") ' Change to suit your needs
Range("B1:B22").Select
Range("C1").Select

For RowNdx = LastRow To 1 Step -1
If Cells(RowNdx, "B").Value = "" Or Cells(RowNdx, "B").Value = "----------" _
Or Cells(RowNdx, "B").Value = "total" Or Cells(RowNdx, "B").Value = _
"subtotal" Then 'Change the "B" to another Column is needed
Rows(RowNdx).Delete
End If
Next RowNdx
End Sub

--
RyGuy



"cardan" wrote:
On Aug 14, 9:06 pm, ryguy7272
wrote:
Sub delete_rows()


Dim RowNdx As Long
Dim LastRow As Long
LastRow = ActiveSheet.UsedRange.Rows.Count
Try this:


For RowNdx = LastRow To 1 Step -1
If Cells(RowNdx, "A").Value = "" Or Cells(RowNdx, "A").Value = "----------"
Or Cells(RowNdx, "A").Value = "total" Or Cells(RowNdx, "A").Value =
"subtotal" Then 'Change the "A" to another Column is needed
Rows(RowNdx).Delete
End If
Next RowNdx
End Sub


Regards,
Ryan---
--
RyGuy


"cardan" wrote:
Hello all,


I am seeking help regarding a new accounting system that imports info
into excel. When it imports, it leaves blank rows as well as rows
with "----------" in it. It also gives totals and subtotals under
certain categories.


I would like to delete the blank rows, delete the rows with the
"---------" as well as delete the rows that have the category totals.
Is there a macro out there where I could identify and delete rows with
these criteria? Any help would be greatly appreciated. Thank you for
your time in advance.- Hide quoted text -


- Show quoted text -


RyGuy, Thank you for the response. The Macro works, for the most
part, however there are some issues on my end. I realized that when I
import the numbers from the accounting program, "blank" cells are
actually not blank. Even though there are no number or anything in
them, Excel still picks up something in them. When I highlight the row
in question and hit delete, then run the macro, it will only then read
the rows as blank and delete them. I tried changing your formula from
"" to 0 but that also does not work.


Also the rows with "totals" in them that I need to get rid of contain
the word total with the heading name as well. ie Total Finance, Total
Design, etc... Is there a way I can get rid of a row in a column
contains the word "Total"?


Thank you for your help. I am very appreciative!- Hide quoted text -


- Show quoted text -


Works great, sorry for my delay in response as well. I greatly
appreciate the effort!

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 236
Default Macro for Deleting Specific Rows?

The solutions posted so far work but work slowly on worksheets where
you have tens of thousands of rows. For that it's better to create a
tag column having a 1 for save and 0 for delete, then sort on the tag
column, select rows having the 0 and delete them all at once.

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
Deleting rows after a specific Value Steel Monkey[_6_] Excel Programming 2 June 2nd 06 01:48 AM
Deleting Specific Rows ScaffoldingDepot Excel Discussion (Misc queries) 2 May 4th 05 04:08 PM
Deleting Specific Rows - urgent alexm999[_12_] Excel Programming 9 February 1st 04 10:19 PM
Deleting specific rows Matt[_20_] Excel Programming 3 November 13th 03 10:41 PM
Deleting rows with specific value from row 1 to 200 solo_razor[_23_] Excel Programming 1 November 4th 03 07:56 AM


All times are GMT +1. The time now is 11:16 AM.

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"