VBA Code not looping each sheet

jamescooper

Well-known Member
Joined
Sep 8, 2014
Messages
834
Hello,

This code doesn't appear to loop through each sheet, any reason why?

Thanks.

VBA Code:
Sub Sheet_Loop()

sheet_count = ActiveWorkbook.Worksheets.Count

'loop through the worksheets in the workbook
For a = 1 To sheet_count

    Range("D10:D1000").Select
        With Selection
        Selection.NumberFormat = "General"
        .Value = .Value
        End With
    
    Range("E10:E1000").Select
    With Selection
        Selection.NumberFormat = "General"
        .Value = .Value
    End With
    
    Range("F10:F1000").Select
    With Selection
        Selection.NumberFormat = "General"
        .Value = .Value
    End With

Next a

End Sub
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
How about
VBA Code:
Sub MM1()
Dim ws As Worksheet
For Each ws In Worksheets
    With Range("D10:F1000")
        .NumberFormat = "General"
        .Value = .Value
    End With
Next ws
End Sub
 
Upvote 0
Nothing is protected.

It doesn't solve all the sheets, it is almost like it doesn't go into the next sheet?
 
Upvote 0
Change to
VBA Code:
Sub MM1()
Dim ws As Worksheet
For Each ws In Worksheets
    With ws.Range("D10:F1000")
        .NumberFormat = "General"
        .Value = .Value
    End With
Next ws
End Sub

Nothing is protected.

It doesn't solve all the sheets, it is almost like it doesn't go into the next sheet?
Did you try the amended code ??
 
Upvote 0
You need to qualify the Range with ws

VBA Code:
With ws.Range("D10:F1000")
 
Last edited:
Upvote 0

Forum statistics

Threads
1,213,557
Messages
6,114,293
Members
448,564
Latest member
ED38

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