Unable to write the worksheet name on the respective worksheet

anuradhagrewal

Board Regular
Joined
Dec 3, 2020
Messages
87
Office Version
  1. 2010
Platform
  1. Windows
Hi Folks
Happy new year
I have these multiple excel sheets in csv format which are name as per the 6 digit employee number for eg : 467733.csv.
Now there are 6 rows starting from A1 to F3000 which lists their working hours for a set of common tasks for a given day.
I import all these csv files into individual worksheets in a single excel file with each worksheet named as for eg 467733.csv etc.
What I need is that in column G2 onwards of all the excel worksheets (in the given excel file) ,the name of the worksheet be automatically be input for the above mentioned range A1 to F3000.
Can anybody suggest a VB script of this.

Please help

Regards

Anu
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Do you mean just something like this ?
VBA Code:
Sub PopulateSheetName()

    Dim ws As Worksheet
    Dim rng As Range
    Dim LastRow As Long
    
    For Each ws In ActiveWorkbook.Worksheets
        With ws
              LastRow = .Cells.Find("*", searchorder:=xlByRows, searchdirection:=xlPrevious).Row
              Set rng = .Range("G1:G" & LastRow)
              rng.Value = .Name
        End With
    Next ws
End Sub
 
Upvote 0
Do you mean just something like this ?
VBA Code:
Sub PopulateSheetName()

    Dim ws As Worksheet
    Dim rng As Range
    Dim LastRow As Long
   
    For Each ws In ActiveWorkbook.Worksheets
        With ws
              LastRow = .Cells.Find("*", searchorder:=xlByRows, searchdirection:=xlPrevious).Row
              Set rng = .Range("G1:G" & LastRow)
              rng.Value = .Name
        End With
    Next ws
End Sub


Absolutely Brilliant Alex
 
Upvote 0

Forum statistics

Threads
1,224,737
Messages
6,180,653
Members
452,992
Latest member
TokugawaIesuma

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