ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   macro for deleting specific columns & rows. Help. Please. No Clue. (https://www.excelbanter.com/excel-programming/429069-macro-deleting-specific-columns-rows-help-please-no-clue.html)

Andrew C

macro for deleting specific columns & rows. Help. Please. No Clue.
 
I'll try to be clear, was thown into this task and need some help. I have
tried looking around for help but never saw a straight solution.

I get a daily .csv file that I need to save after I manually delete certain
info. The file has columns A - AA (Always), but can vary on rows. Column A
has multiple text entries, the only one I need is titled Parent. After that
they have a numeric value in column V, I must delete all rows with the value
of 0 (the actual # zero, there are numbers & zeros in this column, need to
get rid of rows with 0). Then the only columns I NEED are
A,B,D,K,L,N,O,P,Q,R,S,V,W (C,E,F,G,H,I,J,M,T,U,X,Y,Z,AA need to be deleted)

I hop e this is clear, and I really hope that there is a easy solution to
some sort of macro I can run to automate this process on a daily basis to
make my life a little easier.

Thanks,
Drew

Mike H

macro for deleting specific columns & rows. Help. Please. No Clue.
 
Andrew,

Right click your sheet tab, view code and paste this in and run it.

Sub delete_Me()
Dim copyrange As Range, lastrow As Long
lastrow = Cells(Cells.Rows.Count, "A").End(xlUp).Row
Set MyRange = Range("A1:A" & lastrow)
For Each c In MyRange
If UCase(c.Value) = "PARENT" And c.Offset(, 21) < "" _
And c.Offset(, 21) = 0 Then

If copyrange Is Nothing Then
Set copyrange = c.EntireRow
Else
Set copyrange = Union(copyrange, c.EntireRow)
End If
End If
Next
If Not copyrange Is Nothing Then
copyrange.Delete
End If

Range("C:C,E:J,M:M,T:U,X:AA").Delete
End Sub

Mike

"Andrew C" wrote:

I'll try to be clear, was thown into this task and need some help. I have
tried looking around for help but never saw a straight solution.

I get a daily .csv file that I need to save after I manually delete certain
info. The file has columns A - AA (Always), but can vary on rows. Column A
has multiple text entries, the only one I need is titled Parent. After that
they have a numeric value in column V, I must delete all rows with the value
of 0 (the actual # zero, there are numbers & zeros in this column, need to
get rid of rows with 0). Then the only columns I NEED are
A,B,D,K,L,N,O,P,Q,R,S,V,W (C,E,F,G,H,I,J,M,T,U,X,Y,Z,AA need to be deleted)

I hop e this is clear, and I really hope that there is a easy solution to
some sort of macro I can run to automate this process on a daily basis to
make my life a little easier.

Thanks,
Drew


Eduardo

macro for deleting specific columns & rows. Help. Please. No Clue.
 
Hi Andrew,
Take a look at Ron web

http://www.rondebruin.nl/delete.htm



"Andrew C" wrote:

I'll try to be clear, was thown into this task and need some help. I have
tried looking around for help but never saw a straight solution.

I get a daily .csv file that I need to save after I manually delete certain
info. The file has columns A - AA (Always), but can vary on rows. Column A
has multiple text entries, the only one I need is titled Parent. After that
they have a numeric value in column V, I must delete all rows with the value
of 0 (the actual # zero, there are numbers & zeros in this column, need to
get rid of rows with 0). Then the only columns I NEED are
A,B,D,K,L,N,O,P,Q,R,S,V,W (C,E,F,G,H,I,J,M,T,U,X,Y,Z,AA need to be deleted)

I hop e this is clear, and I really hope that there is a easy solution to
some sort of macro I can run to automate this process on a daily basis to
make my life a little easier.

Thanks,
Drew


Andrew C

macro for deleting specific columns & rows. Help. Please. No C
 
Mike-
Thanks for the quick response, your input is a huge help. Soooooo
close, but one problem. The 0 value rows were deleted, the correct columns
were deleted, but the rows in column A were not properly "filtered". I JUST
need the rows with the word "Parent" in column A. After running your code, it
looks like it did not delete the rows with values other than "Parent".

Again, thanks for the help. Hopefully you can respond back with a fix.

Drew
"Mike H" wrote:

Andrew,

Right click your sheet tab, view code and paste this in and run it.

Sub delete_Me()
Dim copyrange As Range, lastrow As Long
lastrow = Cells(Cells.Rows.Count, "A").End(xlUp).Row
Set MyRange = Range("A1:A" & lastrow)
For Each c In MyRange
If UCase(c.Value) = "PARENT" And c.Offset(, 21) < "" _
And c.Offset(, 21) = 0 Then

If copyrange Is Nothing Then
Set copyrange = c.EntireRow
Else
Set copyrange = Union(copyrange, c.EntireRow)
End If
End If
Next
If Not copyrange Is Nothing Then
copyrange.Delete
End If

Range("C:C,E:J,M:M,T:U,X:AA").Delete
End Sub

Mike

"Andrew C" wrote:

I'll try to be clear, was thown into this task and need some help. I have
tried looking around for help but never saw a straight solution.

I get a daily .csv file that I need to save after I manually delete certain
info. The file has columns A - AA (Always), but can vary on rows. Column A
has multiple text entries, the only one I need is titled Parent. After that
they have a numeric value in column V, I must delete all rows with the value
of 0 (the actual # zero, there are numbers & zeros in this column, need to
get rid of rows with 0). Then the only columns I NEED are
A,B,D,K,L,N,O,P,Q,R,S,V,W (C,E,F,G,H,I,J,M,T,U,X,Y,Z,AA need to be deleted)

I hop e this is clear, and I really hope that there is a easy solution to
some sort of macro I can run to automate this process on a daily basis to
make my life a little easier.

Thanks,
Drew


Mike H

macro for deleting specific columns & rows. Help. Please. No C
 
Andrew,

Try this.

Sub delete_Me()
Dim copyrange As Range, lastrow As Long
lastrow = Cells(Cells.Rows.Count, "A").End(xlUp).Row
Set MyRange = Range("A1:A" & lastrow)
For Each c In MyRange
If UCase(c.Value) = "PARENT" And c.Offset(, 21) < "" _
And c.Offset(, 21) = 0 Or UCase(c.Value) < "PARENT" Then
If copyrange Is Nothing Then
Set copyrange = c.EntireRow
Else
Set copyrange = Union(copyrange, c.EntireRow)
End If
End If
Next
If Not copyrange Is Nothing Then
copyrange.delete
End If

Range("C:C,E:J,M:M,T:U,X:AA").Delete
End Sub

Mike
"Andrew C" wrote:

Mike-
Thanks for the quick response, your input is a huge help. Soooooo
close, but one problem. The 0 value rows were deleted, the correct columns
were deleted, but the rows in column A were not properly "filtered". I JUST
need the rows with the word "Parent" in column A. After running your code, it
looks like it did not delete the rows with values other than "Parent".

Again, thanks for the help. Hopefully you can respond back with a fix.

Drew
"Mike H" wrote:

Andrew,

Right click your sheet tab, view code and paste this in and run it.

Sub delete_Me()
Dim copyrange As Range, lastrow As Long
lastrow = Cells(Cells.Rows.Count, "A").End(xlUp).Row
Set MyRange = Range("A1:A" & lastrow)
For Each c In MyRange
If UCase(c.Value) = "PARENT" And c.Offset(, 21) < "" _
And c.Offset(, 21) = 0 Then

If copyrange Is Nothing Then
Set copyrange = c.EntireRow
Else
Set copyrange = Union(copyrange, c.EntireRow)
End If
End If
Next
If Not copyrange Is Nothing Then
copyrange.Delete
End If

Range("C:C,E:J,M:M,T:U,X:AA").Delete
End Sub

Mike

"Andrew C" wrote:

I'll try to be clear, was thown into this task and need some help. I have
tried looking around for help but never saw a straight solution.

I get a daily .csv file that I need to save after I manually delete certain
info. The file has columns A - AA (Always), but can vary on rows. Column A
has multiple text entries, the only one I need is titled Parent. After that
they have a numeric value in column V, I must delete all rows with the value
of 0 (the actual # zero, there are numbers & zeros in this column, need to
get rid of rows with 0). Then the only columns I NEED are
A,B,D,K,L,N,O,P,Q,R,S,V,W (C,E,F,G,H,I,J,M,T,U,X,Y,Z,AA need to be deleted)

I hop e this is clear, and I really hope that there is a easy solution to
some sort of macro I can run to automate this process on a daily basis to
make my life a little easier.

Thanks,
Drew


Andrew C

macro for deleting specific columns & rows. Help. Please. No C
 
Perfect! Thanks so much.

Drew

"Mike H" wrote:

Andrew,

Try this.

Sub delete_Me()
Dim copyrange As Range, lastrow As Long
lastrow = Cells(Cells.Rows.Count, "A").End(xlUp).Row
Set MyRange = Range("A1:A" & lastrow)
For Each c In MyRange
If UCase(c.Value) = "PARENT" And c.Offset(, 21) < "" _
And c.Offset(, 21) = 0 Or UCase(c.Value) < "PARENT" Then
If copyrange Is Nothing Then
Set copyrange = c.EntireRow
Else
Set copyrange = Union(copyrange, c.EntireRow)
End If
End If
Next
If Not copyrange Is Nothing Then
copyrange.delete
End If

Range("C:C,E:J,M:M,T:U,X:AA").Delete
End Sub

Mike
"Andrew C" wrote:

Mike-
Thanks for the quick response, your input is a huge help. Soooooo
close, but one problem. The 0 value rows were deleted, the correct columns
were deleted, but the rows in column A were not properly "filtered". I JUST
need the rows with the word "Parent" in column A. After running your code, it
looks like it did not delete the rows with values other than "Parent".

Again, thanks for the help. Hopefully you can respond back with a fix.

Drew
"Mike H" wrote:

Andrew,

Right click your sheet tab, view code and paste this in and run it.

Sub delete_Me()
Dim copyrange As Range, lastrow As Long
lastrow = Cells(Cells.Rows.Count, "A").End(xlUp).Row
Set MyRange = Range("A1:A" & lastrow)
For Each c In MyRange
If UCase(c.Value) = "PARENT" And c.Offset(, 21) < "" _
And c.Offset(, 21) = 0 Then

If copyrange Is Nothing Then
Set copyrange = c.EntireRow
Else
Set copyrange = Union(copyrange, c.EntireRow)
End If
End If
Next
If Not copyrange Is Nothing Then
copyrange.Delete
End If

Range("C:C,E:J,M:M,T:U,X:AA").Delete
End Sub

Mike

"Andrew C" wrote:

I'll try to be clear, was thown into this task and need some help. I have
tried looking around for help but never saw a straight solution.

I get a daily .csv file that I need to save after I manually delete certain
info. The file has columns A - AA (Always), but can vary on rows. Column A
has multiple text entries, the only one I need is titled Parent. After that
they have a numeric value in column V, I must delete all rows with the value
of 0 (the actual # zero, there are numbers & zeros in this column, need to
get rid of rows with 0). Then the only columns I NEED are
A,B,D,K,L,N,O,P,Q,R,S,V,W (C,E,F,G,H,I,J,M,T,U,X,Y,Z,AA need to be deleted)

I hop e this is clear, and I really hope that there is a easy solution to
some sort of macro I can run to automate this process on a daily basis to
make my life a little easier.

Thanks,
Drew



All times are GMT +1. The time now is 08:07 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com