Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 103
Default Faster Way of looping through cells

Hi All,

Is there a faster way of achieving the following loop:-

It checks through the range and ensures the last value in each cell is a
hard carriage return. It does not act on blank cells.

Sub add_hard_carriage()
Dim start_r As Integer, last_r As Integer
Dim const_Range As Range
Dim wsNM As Worksheet
Dim CurCell As Object 'As Range
Dim var_Chk As Integer

Set wsNM = Sheets("Project Log Form")

start_r = 9 'Start Row on data sheet
last_r = wsNM.Range("A65536").End(xlUp).Row 'last row

Set const_Range = wsNM.Range("T" & start_r & ":T" & last_r) 'Range
containing information

For Each CurCell In const_Range

If CurCell.Value < "" Then

var_Chk = Asc(Right(CurCell, 1))
If var_Chk < 10 Then
CurCell.Value = CurCell.Value & Chr(10)
End If

End If
Next CurCell

End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Faster Way of looping through cells

Sub add_hard_carriage()
Dim start_r As Integer, last_r As Integer
Dim const_Range As Variant
Dim wsNM As Worksheet
Dim CurCell As Variant
Dim var_Chk As Integer
Dim rng as Range
Dim i as Long
Set wsNM = Sheets("Project Log Form")

start_r = 9 'Start Row on data sheet
last_r = wsNM.Range("A65536").End(xlUp).Row 'last row
set rng = wsNM.Range("T" & start_r & ":T" & last_r)
const_Range = rng.Value
i = 0
For Each CurCell In const_Range
i = i + 1
If CurCell < "" Then

var_Chk = Asc(Right(CurCell, 1))
If var_Chk < 10 Then
rng(i).Value = CurCell.Value & Chr(10)
End If

End If
Next CurCell

End Sub


--
Regards,
Tom Ogilvy

"Andibevan" wrote in message
...
Hi All,

Is there a faster way of achieving the following loop:-

It checks through the range and ensures the last value in each cell is a
hard carriage return. It does not act on blank cells.

Sub add_hard_carriage()
Dim start_r As Integer, last_r As Integer
Dim const_Range As Range
Dim wsNM As Worksheet
Dim CurCell As Object 'As Range
Dim var_Chk As Integer

Set wsNM = Sheets("Project Log Form")

start_r = 9 'Start Row on data sheet
last_r = wsNM.Range("A65536").End(xlUp).Row 'last row

Set const_Range = wsNM.Range("T" & start_r & ":T" & last_r) 'Range
containing information

For Each CurCell In const_Range

If CurCell.Value < "" Then

var_Chk = Asc(Right(CurCell, 1))
If var_Chk < 10 Then
CurCell.Value = CurCell.Value & Chr(10)
End If

End If
Next CurCell

End Sub




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Faster Way of looping through cells

How would this make it faster?

"Tom Ogilvy" wrote in message
...
Sub add_hard_carriage()
Dim start_r As Integer, last_r As Integer
Dim const_Range As Variant
Dim wsNM As Worksheet
Dim CurCell As Variant
Dim var_Chk As Integer
Dim rng as Range
Dim i as Long
Set wsNM = Sheets("Project Log Form")

start_r = 9 'Start Row on data sheet
last_r = wsNM.Range("A65536").End(xlUp).Row 'last row
set rng = wsNM.Range("T" & start_r & ":T" & last_r)
const_Range = rng.Value
i = 0
For Each CurCell In const_Range
i = i + 1
If CurCell < "" Then

var_Chk = Asc(Right(CurCell, 1))
If var_Chk < 10 Then
rng(i).Value = CurCell.Value & Chr(10)
End If

End If
Next CurCell

End Sub


--
Regards,
Tom Ogilvy

"Andibevan" wrote in message
...
Hi All,

Is there a faster way of achieving the following loop:-

It checks through the range and ensures the last value in each cell is a
hard carriage return. It does not act on blank cells.

Sub add_hard_carriage()
Dim start_r As Integer, last_r As Integer
Dim const_Range As Range
Dim wsNM As Worksheet
Dim CurCell As Object 'As Range
Dim var_Chk As Integer

Set wsNM = Sheets("Project Log Form")

start_r = 9 'Start Row on data sheet
last_r = wsNM.Range("A65536").End(xlUp).Row 'last row

Set const_Range = wsNM.Range("T" & start_r & ":T" & last_r) 'Range
containing information

For Each CurCell In const_Range

If CurCell.Value < "" Then

var_Chk = Asc(Right(CurCell, 1))
If var_Chk < 10 Then
CurCell.Value = CurCell.Value & Chr(10)
End If

End If
Next CurCell

End Sub






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Faster Way of looping through cells

Don't use it.
--
Regards,
Tom Ogilvy

"Andibevan" wrote in message
...
How would this make it faster?

"Tom Ogilvy" wrote in message
...
Sub add_hard_carriage()
Dim start_r As Integer, last_r As Integer
Dim const_Range As Variant
Dim wsNM As Worksheet
Dim CurCell As Variant
Dim var_Chk As Integer
Dim rng as Range
Dim i as Long
Set wsNM = Sheets("Project Log Form")

start_r = 9 'Start Row on data sheet
last_r = wsNM.Range("A65536").End(xlUp).Row 'last row
set rng = wsNM.Range("T" & start_r & ":T" & last_r)
const_Range = rng.Value
i = 0
For Each CurCell In const_Range
i = i + 1
If CurCell < "" Then

var_Chk = Asc(Right(CurCell, 1))
If var_Chk < 10 Then
rng(i).Value = CurCell.Value & Chr(10)
End If

End If
Next CurCell

End Sub


--
Regards,
Tom Ogilvy

"Andibevan" wrote in message
...
Hi All,

Is there a faster way of achieving the following loop:-

It checks through the range and ensures the last value in each cell is

a
hard carriage return. It does not act on blank cells.

Sub add_hard_carriage()
Dim start_r As Integer, last_r As Integer
Dim const_Range As Range
Dim wsNM As Worksheet
Dim CurCell As Object 'As Range
Dim var_Chk As Integer

Set wsNM = Sheets("Project Log Form")

start_r = 9 'Start Row on data sheet
last_r = wsNM.Range("A65536").End(xlUp).Row 'last row

Set const_Range = wsNM.Range("T" & start_r & ":T" & last_r) 'Range
containing information

For Each CurCell In const_Range

If CurCell.Value < "" Then

var_Chk = Asc(Right(CurCell, 1))
If var_Chk < 10 Then
CurCell.Value = CurCell.Value & Chr(10)
End If

End If
Next CurCell

End Sub








  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 783
Default Faster Way of looping through cells

Tom Ogilvy wrote:
Don't use it.

Substitute the following for the corrersponding portion of Tom Ogilvy's
code; it loops through the array instead of through the worksheet range,
then dumps the array to the worksheet which is where the efficiency
comes from.


i = 0
For Each CurCell In const_Range
i = i + 1
If CurCell < "" Then
var_Chk = Asc(Right(CurCell, 1))
If var_Chk < 10 Then
const_Range(i, 1) = CurCell & Chr(10)
End If
End If
Next CurCell
rng.Value = const_Range

Alan Beban


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Faster Way of looping through cells

As written, the code loops through the array and not the range. If no or
few corrections were needed (which I perceived to be the case), it would
avoid the unnecessary overhead of mindlessly writing the entire array back
to the sheet and incurring that overhead. The question then is how many
corrections have to be made before dumping the entire array back becomes
more beneficial. This would also depend on the extent of the range being
checked.

--
Regards,
Tom Ogilvy

"Alan Beban" wrote in message
...
Tom Ogilvy wrote:
Don't use it.

Substitute the following for the corrersponding portion of Tom Ogilvy's
code; it loops through the array instead of through the worksheet range,
then dumps the array to the worksheet which is where the efficiency
comes from.


i = 0
For Each CurCell In const_Range
i = i + 1
If CurCell < "" Then
var_Chk = Asc(Right(CurCell, 1))
If var_Chk < 10 Then
const_Range(i, 1) = CurCell & Chr(10)
End If
End If
Next CurCell
rng.Value = const_Range

Alan Beban



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
Can faster CPU+larger/faster RAM significantly speed up recalulati jmk_li Excel Discussion (Misc queries) 2 September 28th 05 10:24 AM
Faster Way of looping through cell values Andibevan Excel Discussion (Misc queries) 1 August 12th 05 03:10 PM
Looping on Cells with $x$y D.Parker Excel Programming 4 March 25th 05 11:31 AM
Faster Cycle through Cells Tod Excel Programming 5 January 21st 05 11:57 AM
Looping through Cells Gary Paris[_2_] Excel Programming 5 December 25th 04 08:46 PM


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