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

Selecting cells in a loop routine appears to be terribly inefficient. The code I have is:
Sub errorchk()
Dim s1, s2 As String
Dim r As Variant
Application.ScreenUpdating = False
s1 = "sheet1"
s2 = "sheet2"
For r = 1 To 100
For c = 1 To 26
Cells(r, c).Select
If Sheets(s1).Cells(r, c).Value < Sheets(s2).Cells(r, c).Value Then MsgBox "error at " & ActiveCell.Address
Next c
Next r
MsgBox "Check complete"
Application.ScreenUpdating = True
Range("a1").Select
End Sub

... but would be grateful if anyone has code that can do the same quicker as the check range needs to expand.

Thank you in anticipation.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default .select efficiency

Hi
If I read you code correctly just remove the line
Cells(r, c).Select
your code should work fine without this line as you are referencing the
cells directly

Frank

Lawlera wrote:
Selecting cells in a loop routine appears to be terribly inefficient.
The code I have is:
Sub errorchk()
Dim s1, s2 As String
Dim r As Variant
Application.ScreenUpdating = False
s1 = "sheet1"
s2 = "sheet2"
For r = 1 To 100
For c = 1 To 26
Cells(r, c).Select
If Sheets(s1).Cells(r, c).Value < Sheets(s2).Cells(r, c).Value
Then MsgBox "error at " & ActiveCell.Address Next c
Next r
MsgBox "Check complete"
Application.ScreenUpdating = True
Range("a1").Select
End Sub

.. but would be grateful if anyone has code that can do the same
quicker as the check range needs to expand.

Thank you in anticipation.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 37
Default .select efficiency

Afraid not Frank, as the msgbox relies on the cell being selected to accurately report the location of a variation in values.
I need a way of identifying the particular cells that are being checked in the routine when an error is found.

----- Frank Kabel wrote: -----

Hi
If I read you code correctly just remove the line
Cells(r, c).Select
your code should work fine without this line as you are referencing the
cells directly

Frank

Lawlera wrote:
Selecting cells in a loop routine appears to be terribly inefficient.
The code I have is:
Sub errorchk()
Dim s1, s2 As String
Dim r As Variant
Application.ScreenUpdating = False
s1 = "sheet1"
s2 = "sheet2"
For r = 1 To 100
For c = 1 To 26
Cells(r, c).Select
If Sheets(s1).Cells(r, c).Value < Sheets(s2).Cells(r, c).Value
Then MsgBox "error at " & ActiveCell.Address Next c
Next r
MsgBox "Check complete"
Application.ScreenUpdating = True
Range("a1").Select
End Sub
.. but would be grateful if anyone has code that can do the same

quicker as the check range needs to expand.
Thank you in anticipation.




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 37
Default .select efficiency

Thanks Frank, you put me on the right lines
Sub errorchk(
Dim s1, s2 As Strin
Dim r As Varian
Application.ScreenUpdating = Fals
s1 = "sheet1
s2 = "sheet2
For r = 1 To 10
For c = 1 To 2
'Cells(r, c).Selec
If Sheets(s1).Cells(r, c).Value < Sheets(s2).Cells(r, c).Value Then MsgBox "error at " & Cells(r, c).Addres
Next
Next
MsgBox "Check complete
Application.ScreenUpdating = Tru
Range("a1").Selec
End Sub
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default .select efficiency

Hi
sorry missed that line. Change
Then MsgBox "error at " & ActiveCell.Address
to
Then MsgBox "error at " & Sheets(s1).Cells(r, c).Address

Frank

Lawlera wrote:
Afraid not Frank, as the msgbox relies on the cell being selected to
accurately report the location of a variation in values. I need a way
of identifying the particular cells that are being checked in the
routine when an error is found.

----- Frank Kabel wrote: -----

Hi
If I read you code correctly just remove the line
Cells(r, c).Select
your code should work fine without this line as you are
referencing the cells directly

Frank

Lawlera wrote:
Selecting cells in a loop routine appears to be terribly

inefficient. The code I have is:
Sub errorchk()
Dim s1, s2 As String
Dim r As Variant
Application.ScreenUpdating = False
s1 = "sheet1"
s2 = "sheet2"
For r = 1 To 100
For c = 1 To 26
Cells(r, c).Select
If Sheets(s1).Cells(r, c).Value < Sheets(s2).Cells(r,

c).Value Then MsgBox "error at " & ActiveCell.Address Next
c Next r
MsgBox "Check complete"
Application.ScreenUpdating = True
Range("a1").Select
End Sub
.. but would be grateful if anyone has code that can do the

same quicker as the check range needs to expand.
Thank you in anticipation.



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
Equation Efficiency? Ithaca Excel Worksheet Functions 1 April 29th 09 01:20 AM
Trying to improve efficiency of array formula Anthony[_4_] Excel Worksheet Functions 8 November 25th 08 10:23 AM
Calculation Efficiency (Speed)? Ken Excel Discussion (Misc queries) 2 October 29th 07 12:00 PM
Range efficiency Steven Excel Worksheet Functions 0 December 9th 05 02:15 PM
Question re efficiency in vlookup Mark Stephens Excel Worksheet Functions 1 August 2nd 05 07:31 AM


All times are GMT +1. The time now is 01:19 AM.

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"