Looping a macro through all visible sheets?

GlennJ

Board Regular
Joined
Mar 26, 2018
Messages
59
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
 

GlennJ

Board Regular
Joined
Mar 26, 2018
Messages
59
Office Version
  1. 2016
Platform
  1. Windows
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
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
58,585
Office Version
  1. 365
Platform
  1. Windows
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.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
58,585
Office Version
  1. 365
Platform
  1. Windows
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
 

GlennJ

Board Regular
Joined
Mar 26, 2018
Messages
59
Office Version
  1. 2016
Platform
  1. Windows
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.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
58,585
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

Do you have any hidden sheets?
 

GlennJ

Board Regular
Joined
Mar 26, 2018
Messages
59
Office Version
  1. 2016
Platform
  1. Windows
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
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
58,585
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

That suggests that I14 on those sheets is not actually empty.
 

GlennJ

Board Regular
Joined
Mar 26, 2018
Messages
59
Office Version
  1. 2016
Platform
  1. Windows
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?
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
58,585
Office Version
  1. 365
Platform
  1. Windows
That formula is fine, are you sure it has "" at the end rather than " " (ie a space)
 

GlennJ

Board Regular
Joined
Mar 26, 2018
Messages
59
Office Version
  1. 2016
Platform
  1. Windows
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,133,619
Messages
5,659,913
Members
418,536
Latest member
Tezzies

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
Top