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
 

Some videos you may like

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,218
Office Version
  1. 365
Platform
  1. Windows
Where are you setting the value of lastrow?
 

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
36,680
Office Version
  1. 2010
Platform
  1. Windows
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.
 

coolman

New Member
Joined
Nov 21, 2017
Messages
36
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,122,521
Messages
5,596,652
Members
414,083
Latest member
Mrsash

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