serraostudent1
New Member
- Joined
- Nov 17, 2010
- Messages
- 45
Excel 2013 VBA Assistance needed.
New user to VBA so be patient. I have written code (with some help from videos) to look at a given name in Worksheet POs. Count the number of existing worksheets. If the name is not existing, create a new sheet with the new name, then return to Worksheet POs. I must return to Worksheet POs so that I can select a new name from the drop down list and run the macro again.
Now here is where the trouble lies. Once I have added all new worksheets and return to POs I want to copy and paste the header row into each new worksheet. Problem, how do I tell Excel VBA terms, use the value located in the specified cell (AY2), select that named worksheet, then paste the header row?
Here is what I have so far...
Sub TesttSheet()
'
' TesttSheet Macro
'
'
Sheet_name_to_create = Sheets("POs").Range("AF2").Value
VendorName = Sheets("POs").Range("AF2").Value
For rep = 1 To (Worksheets.Count)
If LCase(Sheets(rep).Name) = LCase(Sheet_name_to_create) Then
MsgBox "This Sheet already exists Roxanne!"
Exit Sub
End If
Next
Sheets.Add After:=Sheets(Sheets.Count)
Sheets(ActiveSheet.Name).Name = Sheet_name_to_create
Sheets(ActiveSheet.Name).Select
Sheets("POs").Select
Sheets("POs").Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
Sheets(ActiveSheet.Name).Name = VendorName
The bolded item above is not working. I need help, desperately, with fixing it. Your assistance is appreciated.
New user to VBA so be patient. I have written code (with some help from videos) to look at a given name in Worksheet POs. Count the number of existing worksheets. If the name is not existing, create a new sheet with the new name, then return to Worksheet POs. I must return to Worksheet POs so that I can select a new name from the drop down list and run the macro again.
Now here is where the trouble lies. Once I have added all new worksheets and return to POs I want to copy and paste the header row into each new worksheet. Problem, how do I tell Excel VBA terms, use the value located in the specified cell (AY2), select that named worksheet, then paste the header row?
Here is what I have so far...
Sub TesttSheet()
'
' TesttSheet Macro
'
'
Sheet_name_to_create = Sheets("POs").Range("AF2").Value
VendorName = Sheets("POs").Range("AF2").Value
For rep = 1 To (Worksheets.Count)
If LCase(Sheets(rep).Name) = LCase(Sheet_name_to_create) Then
MsgBox "This Sheet already exists Roxanne!"
Exit Sub
End If
Next
Sheets.Add After:=Sheets(Sheets.Count)
Sheets(ActiveSheet.Name).Name = Sheet_name_to_create
Sheets(ActiveSheet.Name).Select
Sheets("POs").Select
Sheets("POs").Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
Sheets(ActiveSheet.Name).Name = VendorName
The bolded item above is not working. I need help, desperately, with fixing it. Your assistance is appreciated.