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

Hello,

I have a macro that formats a worksheet by looking for null cells i
Column 'A' and filling them with the previous cells data. It the
checks column 'B' for nulls and deletes the row if a null is found. Th
function I have written is working, but it is very slow:

Dim counter As Integer

Columns(1).Select
ActiveCell.CurrentRegion.Select
areaCount = Selection.Rows.Count

For counter = 1 To areaCount
If Cells(counter, 1).Value = 0 Then
Cells((counter - 1), 1).Copy _
Destination:=Cells(counter, 1)
End If
Next counter

counter = 1

For counter = areaCount To 1 Step -1
If Cells(counter, 2).Value = 0 Then
Rows(counter).Delete
End If
Next counter

This is a dodgy cut 'n' paste job, but it works when the macro is i
its full form.

Can anyone fill me in on how I can do this looping a little mor
efficiently, the other parts of the macro work fine but these ar
adding a lot of time onto the macro's execution.

Cheers,

.tehw

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 100
Default Efficient Looping

H

Try the following. You will have to modify the ranges used

Ton

Sub aaa(
Range("A1:A10").Selec
Selection.SpecialCells(xlCellTypeBlanks).Selec
Selection.Formula = "=r[-1]c
Range("A1:A10").Selec
Application.CutCopyMode = Fals
Selection.Cop
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:=
False, Transpose:=Fals

Range("b1:b10").Selec
Selection.SpecialCells(xlCellTypeBlanks).Selec
first = Tru
For Each ce In Selectio
If first The
rastr = ce.Row & ":" & ce.Ro
first = Fals
Els
rastr = rastr & "," & ce.Row & ":" & ce.Ro
End I
Next c
Range(rastr).Selec
Selection.Delete Shift:=xlU
Range("a1").Selec

End Su

----- tehwa wrote: ----

Hello

I have a macro that formats a worksheet by looking for null cells i
Column 'A' and filling them with the previous cells data. It the
checks column 'B' for nulls and deletes the row if a null is found. Th
function I have written is working, but it is very slow

Dim counter As Intege

Columns(1).Selec
ActiveCell.CurrentRegion.Selec
areaCount = Selection.Rows.Coun

For counter = 1 To areaCoun
If Cells(counter, 1).Value = 0 The
Cells((counter - 1), 1).Copy
Destination:=Cells(counter, 1
End I
Next counte

counter =

For counter = areaCount To 1 Step -
If Cells(counter, 2).Value = 0 The
Rows(counter).Delet
End I
Next counte

This is a dodgy cut 'n' paste job, but it works when the macro is i
its full form

Can anyone fill me in on how I can do this looping a little mor
efficiently, the other parts of the macro work fine but these ar
adding a lot of time onto the macro's execution

Cheers

.tehw


--
Message posted from http://www.ExcelForum.com


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Efficient Looping

acw gave you a good fix for the first part.

for the second part you can do

columns(2).SpecialCells(xlblanks).Entirerow.Delete

--
Regards,
Tom Ogilvy


acw wrote in message
...
Hi

Try the following. You will have to modify the ranges used.


Tony

Sub aaa()
Range("A1:A10").Select
Selection.SpecialCells(xlCellTypeBlanks).Select
Selection.Formula = "=r[-1]c"
Range("A1:A10").Select
Application.CutCopyMode = False
Selection.Copy
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False

Range("b1:b10").Select
Selection.SpecialCells(xlCellTypeBlanks).Select
first = True
For Each ce In Selection
If first Then
rastr = ce.Row & ":" & ce.Row
first = False
Else
rastr = rastr & "," & ce.Row & ":" & ce.Row
End If
Next ce
Range(rastr).Select
Selection.Delete Shift:=xlUp
Range("a1").Select

End Sub

----- tehwa wrote: -----

Hello,

I have a macro that formats a worksheet by looking for null cells in
Column 'A' and filling them with the previous cells data. It then
checks column 'B' for nulls and deletes the row if a null is found.

The
function I have written is working, but it is very slow:

Dim counter As Integer

Columns(1).Select
ActiveCell.CurrentRegion.Select
areaCount = Selection.Rows.Count

For counter = 1 To areaCount
If Cells(counter, 1).Value = 0 Then
Cells((counter - 1), 1).Copy _
Destination:=Cells(counter, 1)
End If
Next counter

counter = 1

For counter = areaCount To 1 Step -1
If Cells(counter, 2).Value = 0 Then
Rows(counter).Delete
End If
Next counter

This is a dodgy cut 'n' paste job, but it works when the macro is in
its full form.

Can anyone fill me in on how I can do this looping a little more
efficiently, the other parts of the macro work fine but these are
adding a lot of time onto the macro's execution.

Cheers,

.tehwa


---
Message posted from http://www.ExcelForum.com/




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Efficient Looping

Tom Ogilvy wrote:
acw gave you a good fix for the first part.

for the second part you can do

columns(2).SpecialCells(xlblanks).Entirerow.Delete

--
Regards,
Tom Ogilvy

geebers...that's about as efficient as I will ev4r get it...

Tony, Tom, thank you kindly

--
Message posted from http://www.ExcelForum.com

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
What's themost efficient way Rod Excel Worksheet Functions 2 December 30th 08 09:31 PM
Efficient linking teh_chucksta Excel Discussion (Misc queries) 3 April 18th 08 11:44 PM
IF and VLOOKUP - how efficient? anthonyg Excel Worksheet Functions 6 April 7th 07 08:45 AM
What is more efficient Brad Excel Discussion (Misc queries) 2 November 20th 06 09:13 PM
More efficient code Rob Bovey Excel Programming 1 July 9th 03 04:46 AM


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