Looping a macro through all visible sheets?

GlennJ

Board Regular
Joined
Mar 26, 2018
Messages
63
Office Version
  1. 2016
Platform
  1. Windows
I have a macro that does exactly what I need. I just need it to do the same thing to all sheets. Any help would be appreciated.

VBA Code:
Sub Name_Sheet()

If Range("I14").Value = "" Then
    'Do nothing
Else
    ActiveSheet.Name = Range("I14").Value
End If

End Sub
 
There isn't another sheet called Dave Smith. Every name is unique. I don't know what else to say.

Thanks for working with me.

I don't want to keep bugging you.
Have great weekend
 
Upvote 0

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
There isn't another sheet called Dave Smith. Every name is unique
Then you shouldn't be getting the error you showed in post#6. You will only get that error if you try to use the same sheet name twice.
 
Upvote 0
If you run this it will tell you what the current sheet name is & what I14 on that sheet contains, when you get an error.
VBA Code:
Sub Name_Sheet()
   Dim Ws As Worksheet
   
   For Each Ws In Worksheets
      On Error Resume Next
      If Ws.Range("I14").Value <> "" Then Ws.Name = Ws.Range("I14").Value
      If Err.Number <> 0 Then MsgBox Ws.Name & vbLf & Ws.Range("I14").Value
      On Error GoTo 0
   Next Ws
End Sub
 
Upvote 0
Somethings weird with my workbook.
I ran your error checker. It show the name of the first sheet and so on. As I click OK to each msg box, it then changes the names exactly as I want them, just not all at once.

I also tried making another fresh workbook to try your original Macro on and it works perfect there.
 
Upvote 0
Do you have any hidden sheets?
 
Upvote 0
yes. There are 9 hidden sheets.
I also noticed that your error checker only give me a message box when here isn't a pickup person
 
Upvote 0
That suggests that I14 on those sheets is not actually empty.
 
Upvote 0
They do have a formula in them =IFERROR(VLOOKUP(I10,'Combine all players'!B1:R1999,17,FALSE),"")
I also tried =VLOOKUP(I10,'Combine all players'!B1:R1999,17,FALSE)

On the sheets without a pickup person, I tried removing the formula and everything works perfect.

I didn't think the formula counted as something in the cell. I need the formula. Does this make sense to you?
 
Upvote 0
That formula is fine, are you sure it has "" at the end rather than " " (ie a space)
 
Upvote 0
yes, that was a direct copy from the sheet =IFERROR(VLOOKUP(I10,'Combine all players'!B1:R1999,17,FALSE),"")

If I follow everything back to the raw data, this is the first formula used =IF(D4=0,"",D4). Could the zeros be coming through some how. The above formula traces back through 4 or 5 other formulas and one column is generated by another macro that is just a copy column and paste.
 
Upvote 0

Forum statistics

Threads
1,214,391
Messages
6,119,247
Members
448,879
Latest member
oksanana

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