Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 360
Default Reuse a script to change the range to rows 1 and 3 only

I want to delete row 1 and 3 if column A is blank. This script checks the
whole sheet and deletes every row if column A is blank. I only want to
delete 1 and 3 if A is blank. For safety sake how can I change the range to
get the union of column 1 and 3 only and delete them? It shouldn't check row
2 only rows 1 and 3.

thanks,

-------------------code---------
Public Sub deleteRows1and3()


Dim rngToSearch As Range
Dim rng As Range
Dim rngToDelete As Range

With ActiveSheet
On Error Resume Next
Columns("A").SpecialCells(xlCellTypeBlanks).Entire Row.Delete
On Error GoTo 0

Set rngToSearch = .Range(.Range("A1"), .Cells(Rows.Count, "A").End(xlUp))
For Each rng In rngToSearch
If Trim(rng.Value) = "" Then
If rngToDelete Is Nothing Then
Set rngToDelete = rng
Else
Set rngToDelete = Union(rng, rngToDelete)
End If
End If

Next rng

If Not rngToDelete Is Nothing Then rngToDelete.EntireRow.Delete
End With
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 360
Default Reuse a script to change the range to rows 1 and 3 only

I decided this script is too complicated and I used another one. I will
repost.

"Janis" wrote:

I want to delete row 1 and 3 if column A is blank. This script checks the
whole sheet and deletes every row if column A is blank. I only want to
delete 1 and 3 if A is blank. For safety sake how can I change the range to
get the union of column 1 and 3 only and delete them? It shouldn't check row
2 only rows 1 and 3.

thanks,

-------------------code---------
Public Sub deleteRows1and3()


Dim rngToSearch As Range
Dim rng As Range
Dim rngToDelete As Range

With ActiveSheet
On Error Resume Next
Columns("A").SpecialCells(xlCellTypeBlanks).Entire Row.Delete
On Error GoTo 0

Set rngToSearch = .Range(.Range("A1"), .Cells(Rows.Count, "A").End(xlUp))
For Each rng In rngToSearch
If Trim(rng.Value) = "" Then
If rngToDelete Is Nothing Then
Set rngToDelete = rng
Else
Set rngToDelete = Union(rng, rngToDelete)
End If
End If

Next rng

If Not rngToDelete Is Nothing Then rngToDelete.EntireRow.Delete
End With
End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Reuse a script to change the range to rows 1 and 3 only

This is very simple code.

Sub deleteR1R3()
LastRow = Cells(Rows.Count, "A").End(xlUp).Row
If (LastRow = 1) And IsEmpty(Range("A1")) Then
Cells(3, "A").EntireRow.Delete
Cells(1, "A").EntireRow.Delete
End If
End

"Janis" wrote:

I want to delete row 1 and 3 if column A is blank. This script checks the
whole sheet and deletes every row if column A is blank. I only want to
delete 1 and 3 if A is blank. For safety sake how can I change the range to
get the union of column 1 and 3 only and delete them? It shouldn't check row
2 only rows 1 and 3.

thanks,

-------------------code---------
Public Sub deleteRows1and3()


Dim rngToSearch As Range
Dim rng As Range
Dim rngToDelete As Range

With ActiveSheet
On Error Resume Next
Columns("A").SpecialCells(xlCellTypeBlanks).Entire Row.Delete
On Error GoTo 0

Set rngToSearch = .Range(.Range("A1"), .Cells(Rows.Count, "A").End(xlUp))
For Each rng In rngToSearch
If Trim(rng.Value) = "" Then
If rngToDelete Is Nothing Then
Set rngToDelete = rng
Else
Set rngToDelete = Union(rng, rngToDelete)
End If
End If

Next rng

If Not rngToDelete Is Nothing Then rngToDelete.EntireRow.Delete
End With
End Sub

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 can change range to select active rows instead of :=Range("S10 ldiaz Excel Discussion (Misc queries) 7 August 29th 08 03:52 PM
How can I change range name definitions as the No. of rows change. [email protected] Excel Programming 1 June 20th 06 03:40 AM
script to change filename jeramie[_2_] Excel Programming 2 February 11th 06 09:36 PM
Change Rows/Columns in range??? 43fan Excel Programming 0 April 1st 04 02:05 PM
Change Rows/Columns in range??? 43fan Excel Programming 0 April 1st 04 02:05 PM


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