Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default HOW CAN I DEFINE A RANGE IN LOOP

Hi

I wanted to delete empty rows from excel sheet in particualar range for
which i wrote a below code and succeeded.

Now i want to delete only row data of A to G column instead of deleting full
row but i am unable to define it in the loop. I have also wrote besides the
code that where i am not able to define.

Please help me somebody to solve it out. I will be really very thankful for
it.
------------------------------------------------
Sub DelEmptyRow()
Dim I As Variant
Rng = Selection.Rows.Count
ActiveCell.Offset(0, 0).Select
Application.ScreenUpdating = False
For i= 1 to rng step 1
If ActiveCell.Value = "" Then
Selection.EntireRow.Delete 'HERE I WANT TO DEFINE I VALUE AND DONT WANT TO
DELETE THE FULL ROW BUT A(I) TO G(I)
'Selection.Delete Shift:=xlUp
Else
ActiveCell.Offset(1, 0).Select
End If
Next I
Application.ScreenUpdating = True
End Sub
-----------------------------------------------------------------
Please mail me at

Thanks.
Best Regards.
Didar.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 747
Default HOW CAN I DEFINE A RANGE IN LOOP

My interpretation:

Sub DelEmptyRow()
Dim rng As Range, rng2 As Range, c As Range

Set rng = Intersect(Selection.EntireRow, Columns(1))
Application.ScreenUpdating = False
For Each c In rng.Cells
If c.Value = "" Then
If rng2 Is Nothing Then Set rng2 = c.Resize(1, 7) Else _
Set rng2 = Union(rng2, c.Resize(1, 7))
End If
Next c
rng2.Delete Shift:=xlUp
Application.ScreenUpdating = True
End Sub

Regards,
Greg

"Didar." wrote:

Hi

I wanted to delete empty rows from excel sheet in particualar range for
which i wrote a below code and succeeded.

Now i want to delete only row data of A to G column instead of deleting full
row but i am unable to define it in the loop. I have also wrote besides the
code that where i am not able to define.

Please help me somebody to solve it out. I will be really very thankful for
it.
------------------------------------------------
Sub DelEmptyRow()
Dim I As Variant
Rng = Selection.Rows.Count
ActiveCell.Offset(0, 0).Select
Application.ScreenUpdating = False
For i= 1 to rng step 1
If ActiveCell.Value = "" Then
Selection.EntireRow.Delete 'HERE I WANT TO DEFINE I VALUE AND DONT WANT TO
DELETE THE FULL ROW BUT A(I) TO G(I)
'Selection.Delete Shift:=xlUp
Else
ActiveCell.Offset(1, 0).Select
End If
Next I
Application.ScreenUpdating = True
End Sub
-----------------------------------------------------------------
Please mail me at

Thanks.
Best Regards.
Didar.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 747
Default HOW CAN I DEFINE A RANGE IN LOOP

Correction to my post:

To avoid an error in case no cells are blank then change the line:
rng2.Delete Shift:=xlUp
To:
If Not rng2 Is Nothing Then rng2.Delete Shift:=xlUp

Regards,
Greg

"Greg Wilson" wrote:

My interpretation:

Sub DelEmptyRow()
Dim rng As Range, rng2 As Range, c As Range

Set rng = Intersect(Selection.EntireRow, Columns(1))
Application.ScreenUpdating = False
For Each c In rng.Cells
If c.Value = "" Then
If rng2 Is Nothing Then Set rng2 = c.Resize(1, 7) Else _
Set rng2 = Union(rng2, c.Resize(1, 7))
End If
Next c
rng2.Delete Shift:=xlUp
Application.ScreenUpdating = True
End Sub

Regards,
Greg


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
Define Name range Gotroots Excel Discussion (Misc queries) 10 December 19th 09 11:30 AM
Name to define a chart range mge Excel Discussion (Misc queries) 3 May 14th 09 06:31 PM
Define a range jlclyde Excel Discussion (Misc queries) 2 April 17th 08 08:26 PM
Define a range based on another named range Basil Excel Worksheet Functions 2 February 21st 05 01:47 PM
Define Range Name Wayne Huxman Excel Programming 3 November 21st 04 09:56 PM


All times are GMT +1. The time now is 01:16 PM.

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"