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

Hi,

Not sure if anyone can explain why I'm getting a run time error '91'
(object variable or with block variable not set) when I try to run this
nested loop - I'm out of thoughts in trying to troubleshoot it. Any
thoughts would be greatly appreciated!

What I'm trying to - I have a large sheet of data and I'll need to
correct some formulas that occur in multiple columns and rows. So I
was just trying to loop through the appropriate columns and rows by
finding the appropriate ones, and correct each formula cell
individually.

Thanks! Clair.


With ActiveSheet.Columns(2)
Set c = .Find(What:=" Total", LookIn:=xlValues, LookAt:=xlPart)
If Not c Is Nothing Then
firstaddress = c.Address
Do
c.Select
With ActiveSheet.Rows("3:3")
Set d = .Find(What:="% Utilization", LookIn:=xlValues,
LookAt:=xlPart)
If Not d Is Nothing Then
dfirstaddress = d.Address
Do
d.Select
' loop actions here
Set d = .FindNext(d)
Loop While Not d Is Nothing And d.Address <
dfirstaddress
End If
End With
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address < firstaddress
End If
End With

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Nested with loops

you can't findnext on the first find after you have done an subsequent find.
However, you don't have to. Try it this way:

Sub aaa()
Dim c As Range, d As Range
Dim dfirstaddress As String
Dim firstaddress As String
With ActiveSheet.Columns(2)
Set c = .Find(What:=" Total", _
After:=Range("B65536"), LookIn:=xlValues, LookAt:=xlPart)
If Not c Is Nothing Then
firstaddress = c.Address
Do
c.Select
Selection.Interior.ColorIndex = 3
With ActiveSheet.Rows("3:3")
Set d = .Find(What:="% Utilization", LookIn:=xlValues, LookAt:=xlPart)
If Not d Is Nothing Then
dfirstaddress = d.Address
Do
d.Select
' loop actions here
Set d = .FindNext(d)
Loop While Not d Is Nothing And d.Address < dfirstaddress
End If
End With
Set c = .Find(What:=" Total", _
After:=c, LookIn:=xlValues, LookAt:=xlPart)
Loop While Not c Is Nothing And c.Address < firstaddress
End If
End With
End Sub

--
Regards,
Tom Ogilvy

"Clair" wrote:

Hi,

Not sure if anyone can explain why I'm getting a run time error '91'
(object variable or with block variable not set) when I try to run this
nested loop - I'm out of thoughts in trying to troubleshoot it. Any
thoughts would be greatly appreciated!

What I'm trying to - I have a large sheet of data and I'll need to
correct some formulas that occur in multiple columns and rows. So I
was just trying to loop through the appropriate columns and rows by
finding the appropriate ones, and correct each formula cell
individually.

Thanks! Clair.


With ActiveSheet.Columns(2)
Set c = .Find(What:=" Total", LookIn:=xlValues, LookAt:=xlPart)
If Not c Is Nothing Then
firstaddress = c.Address
Do
c.Select
With ActiveSheet.Rows("3:3")
Set d = .Find(What:="% Utilization", LookIn:=xlValues,
LookAt:=xlPart)
If Not d Is Nothing Then
dfirstaddress = d.Address
Do
d.Select
' loop actions here
Set d = .FindNext(d)
Loop While Not d Is Nothing And d.Address <
dfirstaddress
End If
End With
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address < firstaddress
End If
End With


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
Help with nested for loops [email protected] Excel Discussion (Misc queries) 5 May 2nd 07 05:30 PM
Help with nested for loops [email protected] Excel Worksheet Functions 5 May 2nd 07 05:30 PM
nested loops jer Excel Programming 2 January 15th 06 09:09 PM
Help on nested loops Jan Lukszo Excel Programming 1 July 29th 04 08:41 AM
Nested loops?? CG Rosén Excel Programming 1 June 22nd 04 08:07 PM


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