bring digits of locations for the sheets names in specific column

abdelfattah

Well-known Member
Joined
May 3, 2019
Messages
1,429
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
hello
I have many sheets are different names PUR, SSS ,MAN56 ,JAN12 , so if sheet PUR in first and the SSS is the second … etc. then should bring the all sheets with digits of locations in COL A ,B like this
COL A COL B
LOCATION NAME
1 PUR
2 SSS
3 MAN56
4 JAN12
thanks in advance
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
This macro will list the sheet indexes in Column A and the name of the sheet tab in that index position...
VBA Code:
Sub SheetIndexesAndNames()
  Dim X As Long
  For X = 1 To Sheets.Count
    Cells(X, "A").Resize(, 2).Value = Array(X, Sheets(X).Name)
  Next
End Sub
 
Upvote 0
excellent ! may you also add to your code the headers in row1 LOCATION , NAME ?
 
Upvote 0
Give this a try...
VBA Code:
Sub SheetIndexesAndNames()
  Dim X As Long
  Range("A1:B1") = Split("LOCATION NAME")
  For X = 1 To Sheets.Count
    Cells(X + 1, "A").Resize(, 2).Value = Array(X, Sheets(X).Name)
  Next
End Sub
 
Upvote 0
thanks rick that's great ! just I would bold and highlight the headers by yellowy and make the data from row2 highlight by light blue the cells and red the data and make borders like the table and the data should be in center
like this image
de .xlsm
AB
1LOCATIONNAME
21STOCK
32FIRST
43SECOND
54THIRD
65FOURTH
76result
result

thanks again
 
Upvote 0
Does this do what you want...
VBA Code:
Sub SheetIndexesAndNames()
  Dim X As Long
  With Range("A1:B1")
    .Value = Split("LOCATION NAME")
    .Interior.Color = vbYellow
    .BorderAround xlContinuous, xlThin
    .Borders(xlInsideVertical).Weight = xlThin
    .Font.Bold = True
  End With
  For X = 1 To Sheets.Count
    Cells(X + 1, "A").Resize(, 2).Value = Array(X, Sheets(X).Name)
    Cells(X + 1, "A").BorderAround xlContinuous, xlThin
    Cells(X + 1, "B").BorderAround xlContinuous, xlThin
  Next
  With Range("A2:B" & Sheets.Count + 1)
    .Interior.ColorIndex = 37
    .Font.Color = vbRed
  End With
  Columns("A:B").AutoFit
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,214,651
Messages
6,120,744
Members
448,989
Latest member
mariah3

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