maomaodang
New Member
- Joined
- Nov 16, 2018
- Messages
- 6
Hi,
I have 20 excel tabs, which each representing a restaurant outlet. I would like to have the tab name indicating in cell B1 to cell M1 for each tab except this Master tab.
Below is my code:
Sub Insert_Tab_Name()
Dim sht As Worksheet
For Each sht In ActiveWorkbook.Worksheets
If sht.Name <> "Master" Then
Range("B1", "M1").Formula = "=Mid(Cell(""filename"",B1),Find(""]"",Cell(""filename""))+1,255)"
End If
Next sht
End Sub
It works on the active tab, but not for the rest of the tabs ie I have to run the macro 20 times rather than 1 time. Anyone can help to check what's wrong with my formula please? Many thanks!
I have 20 excel tabs, which each representing a restaurant outlet. I would like to have the tab name indicating in cell B1 to cell M1 for each tab except this Master tab.
Below is my code:
Sub Insert_Tab_Name()
Dim sht As Worksheet
For Each sht In ActiveWorkbook.Worksheets
If sht.Name <> "Master" Then
Range("B1", "M1").Formula = "=Mid(Cell(""filename"",B1),Find(""]"",Cell(""filename""))+1,255)"
End If
Next sht
End Sub
It works on the active tab, but not for the rest of the tabs ie I have to run the macro 20 times rather than 1 time. Anyone can help to check what's wrong with my formula please? Many thanks!