Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 36
Default preset range

I have the following Module:
Sub DelEmptyRow()
Rng = Selection.Rows.Count
ActiveCell.Offset(0, 0).Select
Application.ScreenUpdating = False
For i = 1 To Rng
If ActiveCell.Value = 0 Then 'You can replace "" with 0 to delete rows
with 'the value zero
Selection.EntireRow.Delete
ElseIf ActiveCell.Value = "Company" Then
Selection.EntireRow.Delete
ElseIf ActiveCell.Value = "Controlling Area :" Then
Selection.EntireRow.Delete
ElseIf ActiveCell.Value = "Proj. number" Then
Selection.EntireRow.Delete
Else
ActiveCell.Offset(1, 0).Select
End If
Next i
End Sub

What can I add so I don't have to select the data and use a pre determined
range of "A8:Z300" as the selection set. Also is there a way to make the code
smaller?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default preset range

This is one alternative:

Sub DelEmptyRow()
Dim Rng As Range, sRng As Range, i As Long, col As Long
col = ActiveCell.Column
Set Rng = Range(ActiveCell.Address & ":" & _
ActiveSheet.Cells(Rows.Count, col). _
End(xlUp).Address)
For i = Rng.Rows.Count To 1 Step -1
Set sRng = ActiveSheet.Cells(i, col)
If sRng = "Company" Or sRng = "Controlling Area :" Or _
sRng = "Proj. number" Then
sRng.EntireRow.Delete
End If
Next
End Sub


"Novice Lee" wrote:

I have the following Module:
Sub DelEmptyRow()
Rng = Selection.Rows.Count
ActiveCell.Offset(0, 0).Select
Application.ScreenUpdating = False
For i = 1 To Rng
If ActiveCell.Value = 0 Then 'You can replace "" with 0 to delete rows
with 'the value zero
Selection.EntireRow.Delete
ElseIf ActiveCell.Value = "Company" Then
Selection.EntireRow.Delete
ElseIf ActiveCell.Value = "Controlling Area :" Then
Selection.EntireRow.Delete
ElseIf ActiveCell.Value = "Proj. number" Then
Selection.EntireRow.Delete
Else
ActiveCell.Offset(1, 0).Select
End If
Next i
End Sub

What can I add so I don't have to select the data and use a pre determined
range of "A8:Z300" as the selection set. Also is there a way to make the code
smaller?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default preset range

Are those three text strings you are testing for all located in the same
column (if so, which one) or can the be located in any of the columns within
the range A8:Z300?

--
Rick (MVP - Excel)


"Novice Lee" wrote in message
...
I have the following Module:
Sub DelEmptyRow()
Rng = Selection.Rows.Count
ActiveCell.Offset(0, 0).Select
Application.ScreenUpdating = False
For i = 1 To Rng
If ActiveCell.Value = 0 Then 'You can replace "" with 0 to delete rows
with 'the value zero
Selection.EntireRow.Delete
ElseIf ActiveCell.Value = "Company" Then
Selection.EntireRow.Delete
ElseIf ActiveCell.Value = "Controlling Area :" Then
Selection.EntireRow.Delete
ElseIf ActiveCell.Value = "Proj. number" Then
Selection.EntireRow.Delete
Else
ActiveCell.Offset(1, 0).Select
End If
Next i
End Sub

What can I add so I don't have to select the data and use a pre determined
range of "A8:Z300" as the selection set. Also is there a way to make the
code
smaller?


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 36
Default preset range

Rick

Yes they are all in column a

"Rick Rothstein" wrote:

Are those three text strings you are testing for all located in the same
column (if so, which one) or can the be located in any of the columns within
the range A8:Z300?

--
Rick (MVP - Excel)


"Novice Lee" wrote in message
...
I have the following Module:
Sub DelEmptyRow()
Rng = Selection.Rows.Count
ActiveCell.Offset(0, 0).Select
Application.ScreenUpdating = False
For i = 1 To Rng
If ActiveCell.Value = 0 Then 'You can replace "" with 0 to delete rows
with 'the value zero
Selection.EntireRow.Delete
ElseIf ActiveCell.Value = "Company" Then
Selection.EntireRow.Delete
ElseIf ActiveCell.Value = "Controlling Area :" Then
Selection.EntireRow.Delete
ElseIf ActiveCell.Value = "Proj. number" Then
Selection.EntireRow.Delete
Else
ActiveCell.Offset(1, 0).Select
End If
Next i
End Sub

What can I add so I don't have to select the data and use a pre determined
range of "A8:Z300" as the selection set. Also is there a way to make the
code
smaller?



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
Change Preset Columns Bernie Excel Discussion (Misc queries) 1 January 7th 10 03:30 PM
preset table RobcPettit[_2_] Excel Programming 2 October 18th 08 12:35 AM
Clear cells to a preset value Emerogork Excel Worksheet Functions 2 August 24th 07 02:02 AM
Clear cells to a preset value Emerogork Excel Worksheet Functions 0 August 24th 07 12:03 AM
Is there anyway to add more than the preset 265 columns in Excel? CarlaWood Excel Discussion (Misc queries) 6 December 8th 05 10:09 PM


All times are GMT +1. The time now is 04:09 PM.

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"