|
-
Oct 1st, 2010, 12:56 AM
#1
Thread Starter
Frenzied Member
[RESOLVED] Switching worksheets
Hi,
Becase of the way my project has expanded, I want to switch worksheets
in the middle of a For-Next Loop.
The trigger is when the Loop index reaches 13921.
However the line,
If Indx > 13921 Then With Worksheets("Sheet2")
invokes
Compile error: End If without block If
Can this be circumvented, or should I try a different approach?
Thanks, ABB
-
Oct 1st, 2010, 03:53 AM
#2
Re: Switching worksheets
is this a for each loop or for var =
show the code for the loop and leading into the loop
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Oct 1st, 2010, 05:58 AM
#3
Re: Switching worksheets
That should be:
Code:
If Indx > 13921 Then
With Worksheets("Sheet2")
...
End With
End If
-
Oct 1st, 2010, 08:22 PM
#4
Thread Starter
Frenzied Member
Re: Switching worksheets
Thanks very much Anhn and Westconn. It was a For-Next. I tried that Anhn but I wanted the same
'with' code to execute regardless of Indx, but Indx to change With to point at another sheet at 13921.
I ended up using a variable then
If Indx > 13921 Then SheetIWant = "Sheet2"
myvalue = Worksheets(SheetIWant).Cells(row, col)
Seems to work... 
Regards, ABB
-
Oct 6th, 2010, 08:53 AM
#5
Re: Switching worksheets
Code:
If Indx > 13921 Then myvalue = Worksheets("Sheet2").Cells(row, col)
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Oct 8th, 2010, 06:32 AM
#6
Thread Starter
Frenzied Member
Re: [RESOLVED] Switching worksheets
Thanks Koolsid, I should have known that.
Regards, ABB
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|