record worksheet name into a cell

coolman

New Member
Joined
Nov 21, 2017
Messages
36
hello

i have been trying to get the program to record the worksheet name into a cell but i could not get it working.

anyone can advice? here is my code

Sub ButtonPRGenerator_Click()


x = MsgBox("Welcome to Purchase Request Generator.", vbOKOnly + vbInformation, "Purchase Request Generator")


Dim a, b
Sheets.Add after:=Sheets(Sheets.Count)
a = Sheets.Count
b = InputBox("Please enter the sheet name for Purchase Summary Report. Do note that the name of the worksheet must not be similar as the previous worksheets.")
Sheets(a).Name = b


With Worksheets("purchase request list").Cells(lastrow + 1, 8)
.Value = Sheets(a).Name
.VerticalAlignment = xlCenter
.HorizontalAlignment = xlLeft
.Borders(xlEdgeLeft).LineStyle = xlContinuous
.Borders(xlEdgeRight).LineStyle = xlContinuous
.Borders(xlEdgeTop).LineStyle = xlContinuous
.Borders(xlEdgeBottom).LineStyle = xlContinuous
.WrapText = True
End With


PRGeneratorS1.Show


End Sub
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Where are you setting the value of lastrow?
 
Upvote 0
i have been trying to get the program to record the worksheet name into a cell but i could not get it working.

anyone can advice?
In what way is your code not working correctly? Structurally, there is nothing wrong with the code although I would think you might want to calculate a value for your "lastrow" variable so that the object of your With statement does not always put the sheet name in cell H1.
 
Upvote 0
i forgot to put in the last row calculation.

after adding it, the program is able to work

thank you for all of your advice

In what way is your code not working correctly? Structurally, there is nothing wrong with the code although I would think you might want to calculate a value for your "lastrow" variable so that the object of your With statement does not always put the sheet name in cell H1.
 
Upvote 0

Forum statistics

Threads
1,224,905
Messages
6,181,662
Members
453,059
Latest member
jkevin

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