Quick lil Macro

cav~firez22

Well-known Member
Joined
Jun 21, 2006
Messages
543
Could someone help me with a quick little macro...?

Im trying to get something to do the following

copy the active sheet to the end of the workbook.
rename that copy to the value of cell B2


Think someone could help with this??
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.

Jonmo1

MrExcel MVP
Joined
Oct 12, 2006
Messages
44,061
Code:
Sub Macro1()
    x = ActiveSheet.Range("b2").Value
    ActiveSheet.Copy after:=Sheets(Sheets.Count)
    ActiveSheet.Name = x
End Sub
 

cav~firez22

Well-known Member
Joined
Jun 21, 2006
Messages
543
wOW, talk about quick. Thank.

how about a few more parts of it??

Im stuck trying to get a range created from the sheet names.

Each time the sheet is copied, and the name is applied from the value of the cell.... Im trying to get it to copy the name of the sheet to Cell A40, on sheet Template. and then as more sheets get created, to keep filling in the sheet names in the first empy cell below A40 on sheet template..


sounds hard, seems hard, as im stuck... :)

thanks
 

Jonmo1

MrExcel MVP
Joined
Oct 12, 2006
Messages
44,061
Code:
Sub Macro1() 
    LR = Sheets("template").Cells(Rows.Count,"A").End(xlup).Row + 1
    x = ActiveSheet.Range("b2").Value 
    ActiveSheet.Copy after:=Sheets(Sheets.Count) 
    ActiveSheet.Name = x 
    Sheets("template").Range("A" & LR).Value = x
End Sub
 

cav~firez22

Well-known Member
Joined
Jun 21, 2006
Messages
543
Thanks for that. works great.
 

cav~firez22

Well-known Member
Joined
Jun 21, 2006
Messages
543
Ok, one more question... i think

Code:
Cells.Select
Selection.Locked = True
Selection.FormulaHidden = False
ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:= False

How can i get this to Password the protection, as i dont want the user to know the password.

Thanx much
 

Jonmo1

MrExcel MVP
Joined
Oct 12, 2006
Messages
44,061
Code:
With ActiveSheet
   .Cells.Locked = True
   .Cells.FormulaHidden = False
   .Protect "Password", DrawingObjects:=False, Contents:=True, Scenarios:=False
End With

You will need to include the password in any code you have that UNprotects the sheet..

.Unprotect "Password"
 

cav~firez22

Well-known Member
Joined
Jun 21, 2006
Messages
543
for
Range("A" & Rows.Count).End(xlUp).Offset(1).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False


How would i make it copy all the formats and such as well? currently its just the values.
 

Jonmo1

MrExcel MVP
Joined
Oct 12, 2006
Messages
44,061
With 2 lines, one for the values, then one for the formats..
Code:
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
 

Forum statistics

Threads
1,181,734
Messages
5,931,731
Members
436,800
Latest member
abowalid98

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