Hi,
I've written some code in VBA which creates a new tab based on a cell value. As you can imagine this cell value can change.
After creating this tab i wanted to paste some information into it. However, I cannot call the tab; i'm getting error 9 subscript out of range. Or Object required depending on how i tweak the code
I've written some code in VBA which creates a new tab based on a cell value. As you can imagine this cell value can change.
After creating this tab i wanted to paste some information into it. However, I cannot call the tab; i'm getting error 9 subscript out of range. Or Object required depending on how i tweak the code
Code:
Sub Save_data2()
'Copy A Range of Data
Worksheets("ROI - Post Visit").Range("J30").Copy
'PasteSpecial Values Only
Worksheets("ROI - Post Visit").Range("S2").PasteSpecial Paste:=xlPasteValues
Dim TabName As Range
Set TabName = Worksheets("ROI - Post Visit").Range("S2")
'Creat New Tab with name of property
Sheets.Add(After:=Sheets(Sheets.Count)).Name = TabName
Dim NewSheet As Worksheet
Set NewSheet = Worksheets("ROI - Post Visit").Range("S12").Value
'copy worksheet
Worksheets("ROI - Post Visit").Range("D2:R34").Copy
'Paste
Worksheets("NewSheet").Range("D2:R34").Paste
Worksheets("NewSheet").Range("D2:R34").Copy
Worksheets("NewSheet").Range("D2:R34").PasteSpecial Paste:=xlPasteValues
Last edited: