My code works until I nest it inside another For Loop, am I missing something

jpk89

New Member
Joined
Aug 17, 2015
Messages
13
Sub Move3Mo()

Dim CL As Range
Dim RNG As Range
Dim WS As Worksheet
Application.ScreenUpdating = False


For Each WS in ThisWorkBook.Worksheets

Set RNG = Range("c9:C200")

For Each CL In RNG

If CL.HasFormula = True Then
CL.Offset(, 3) = CL.Value

ElseIf IsNumeric(CL) = True Then
CL.Offset(, 3) = CL.Value

Else

End If

Next CL

Next WS

End Sub
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Do you want to repeat the inner loop code for all worksheet from outer loop? If yes, then try changing your line to:

Code:
Set RNG = [COLOR=#0000ff]WS.[/COLOR]Range("c9:C200")
 
Upvote 0
Thanks, I always get hung up on how to correctly specify an object. If you don't mind, why is range insufficient and something like workbooks.ws.range is unnecessary?
 
Upvote 0
If you don't mention the parent object, then VBA by default refers to currently active object as its parent.

If you have Sheet1 active then you can't write Range("A1:A10") to access range from Sheet2. That's because in absence of a parent qualifier object VBA will look for it in Sheet1. If you want to refer to that range in Sheet2, then you need to specify that: Sheets("Sheet2").Range("A1:A10").

Similarly if you write Sheets("Sheet1") to refer to a worksheet, then VBA will look for Sheet1 in currently active workbook; not other workbooks that you might have open at the moment.
 
Upvote 0

Forum statistics

Threads
1,223,262
Messages
6,171,080
Members
452,377
Latest member
bradfordsam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top