Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Scottie
 
Posts: n/a
Default delete columns and rows-cells equalling zero or any selected value

Want to select a range of cells horizonally and then delete column when value
is zero. Same with rows, select cells vertically and then delete rows when
value is zero.
THX gang. I'd trade my mother for all your help...
  #2   Report Post  
Bernie Deitrick
 
Posts: n/a
Default

Scottie,

I hope your mother doesn't visit microsoft.public.excel.worksheet.functions
;-)

Try the sub below.

HTH,
Bernie
MS Excel MVP


Sub ScottieDeleteZero()
Dim i As Integer
If Selection.Rows.Count 1 And _
Selection.Columns.Count 1 Then
MsgBox "Select either a single row or column of cells"
Exit Sub
End If
If Selection.Rows.Count 1 Then
For i = Selection.Cells.Count To 1 Step -1
If Selection.Cells(i).Value = 0 Then
Selection.Cells(i).EntireRow.Delete
End If
Next i
Else
For i = Selection.Cells.Count To 1 Step -1
If Selection.Cells(i).Value = 0 Then
Selection.Cells(i).EntireColumn.Delete
End If
Next i
End If
End Sub


"Scottie" wrote in message
...
Want to select a range of cells horizonally and then delete column when

value
is zero. Same with rows, select cells vertically and then delete rows

when
value is zero.
THX gang. I'd trade my mother for all your help...



  #3   Report Post  
Scottie
 
Posts: n/a
Default

You're too damn good MVP...

"Bernie Deitrick" wrote:

Scottie,

I hope your mother doesn't visit microsoft.public.excel.worksheet.functions
;-)

Try the sub below.

HTH,
Bernie
MS Excel MVP


Sub ScottieDeleteZero()
Dim i As Integer
If Selection.Rows.Count 1 And _
Selection.Columns.Count 1 Then
MsgBox "Select either a single row or column of cells"
Exit Sub
End If
If Selection.Rows.Count 1 Then
For i = Selection.Cells.Count To 1 Step -1
If Selection.Cells(i).Value = 0 Then
Selection.Cells(i).EntireRow.Delete
End If
Next i
Else
For i = Selection.Cells.Count To 1 Step -1
If Selection.Cells(i).Value = 0 Then
Selection.Cells(i).EntireColumn.Delete
End If
Next i
End If
End Sub


"Scottie" wrote in message
...
Want to select a range of cells horizonally and then delete column when

value
is zero. Same with rows, select cells vertically and then delete rows

when
value is zero.
THX gang. I'd trade my mother for all your help...




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 do i delete the extra empty rows and columns that i dont need. lindaY Excel Discussion (Misc queries) 3 March 20th 05 03:48 PM
How to delete extraneous rows and columns Bruce Gray Excel Discussion (Misc queries) 5 February 26th 05 05:30 PM
extract data from a range of cells in rows or columns when a date. Dartyon Excel Worksheet Functions 0 February 24th 05 10:37 PM
The $ thing to lock cells at rows or columns [email protected] Excel Discussion (Misc queries) 2 December 27th 04 11:57 AM
How do you select two cells in different rows and columns with ou. M.G Excel Discussion (Misc queries) 3 December 17th 04 11:39 PM


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