Macro to go through a list

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,194
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi Everyone,

I have this code which currently runs on a sheet called "Amav"
I'd like to Make a list of sheet names down column A (From 2 to last row) and have the macro run on each name
How do I adjust the code so it does this?
Thanks
Tony

VBA Code:
Sub Text_to_Numbers()

sht = "Amav"
           With sht.Range("I2:I" & Cells(Rows.Count, "I").End(xlUp).Row) 'text to numbers
            .NumberFormat = "General"
            .Value = .Value
            End With

End Sub
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
try this
Sub Dosomething()

' From - vba run macro on all sheets - Bing
Dim xSh As Worksheet
Application.ScreenUpdating = False
For Each xSh In Worksheets
xSh.Select
Call RunCode
Next
Application.ScreenUpdating = True
End Sub
Sub RunCode()
With Range("I2:I" & Cells(Rows.Count, "I").End(xlUp).Row) 'text to numbers
.NumberFormat = "General"
.Value = .Value
End With
End Sub
 
Upvote 0
Hi Act Porta,
Thanks for your help but I really need to make a list of the sheet names Down column A and only run on those as I said above, I'm not looking to do this on every sheet.
Thanks Anyway
Tony
 
Upvote 0
If you have a list of sheets already in column A try this
VBA Code:
Sub Dosomething2()
Dim sheet_name As Range
 For Each sheet_name In Sheets("sheet1").Range("A2:A" & Cells(Rows.Count, "A").End(xlUp).Row)
  If sheet_name.Value = "" Then
   Exit For
   Else
   Sheets(sheet_name.Value).Select
Call RunCode
End If
Next sheet_name

Application.ScreenUpdating = True
End Sub
Sub RunCode()
With Range("I2:I" & Cells(Rows.Count, "I").End(xlUp).Row) 'text to numbers
.NumberFormat = "General"
.Value = .Value
End With
End Sub
 
Upvote 0
Try to create list of sheet's name from cell A1 sheet Amv, then text to numbers for all sheets :
VBA Code:
Sub Text_to_Numbers()
Dim sht As Worksheet
For i = 1 To Sheets.Count
    Sheets("Amv").Range("A" & i).Value = Sheets(i).Name
Next
    For Each sht In Sheets
        With sht.Range("I2:I" & Cells(Rows.Count, "I").End(xlUp).Row)
            .NumberFormat = "General"
            .Value = .Value
        End With
    Next
End Sub

In case list of sheet's name is helper to run macro, then it can be removed out:
VBA Code:
Sub Text_to_Numbers()
Dim sht As Worksheet
    For Each sht In Sheets
        With sht.Range("I2:I" & Cells(Rows.Count, "I").End(xlUp).Row)
            .NumberFormat = "General"
            .Value = .Value
        End With
    Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,867
Messages
6,122,002
Members
449,059
Latest member
mtsheetz

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