Adding a New Tab-and Naming it from a Cell Name

C

caldog

All I am trying to add a new worksheet and name it what ever the cell value
is from my main sheet. The name will always be a number plus one. Example
in my "Inputsheet' in column BA row 9 is a number 1701, so with what I am
trying to do is ref BA9 and copy it to BA10 plus one (cell BA10 then should
say 1702).

I have attached my code which is not working (got part of this code from Ron
de Bruin web site):

Private Sub CreateNewSheet1_Click()
Dim LastRow As Long
Dim rng As Range

With ActiveSheet
LastRow = .Cells(.Rows.Count, "BA").End(xlUp).Row
With rng.Parent
.Select
.Range(LastRow).Select
End With
LastRow = ActiveCell.FormulaR1C1 = "=R[-1]C+1"
Selection.Copy
ActiveSheet.Range(LastRow).Select
ActiveSheet.Paste

End With

Sheets.Add After:=Sheets(Sheets.Count)
Sheets(Sheets.Count).Name = LastRow

ActiveSheet.Range("A1").Select

End Sub
 
P

Per Jessen

Hi

Look at this:

Private Sub CreateNewSheet1_Click()
Dim LastRow As Long

LastRow = Cells(Rows.Count, "BA").End(xlUp).Row
Range("BA" & LastRow + 1) = Range("BA" & LastRow).Value + 1

NewShName = Range("BA" & LastRow + 1).Value

Sheets.Add After:=Sheets(Sheets.Count)
ActiveSheet.Name = NewShName
End Sub

Regards,
Per
 
C

caldog

Worked great Thanks
Per Jessen said:
Hi

Look at this:

Private Sub CreateNewSheet1_Click()
Dim LastRow As Long

LastRow = Cells(Rows.Count, "BA").End(xlUp).Row
Range("BA" & LastRow + 1) = Range("BA" & LastRow).Value + 1

NewShName = Range("BA" & LastRow + 1).Value

Sheets.Add After:=Sheets(Sheets.Count)
ActiveSheet.Name = NewShName
End Sub

Regards,
Per

caldog said:
All I am trying to add a new worksheet and name it what ever the cell
value
is from my main sheet. The name will always be a number plus one.
Example
in my "Inputsheet' in column BA row 9 is a number 1701, so with what I am
trying to do is ref BA9 and copy it to BA10 plus one (cell BA10 then
should
say 1702).

I have attached my code which is not working (got part of this code from
Ron
de Bruin web site):

Private Sub CreateNewSheet1_Click()
Dim LastRow As Long
Dim rng As Range

With ActiveSheet
LastRow = .Cells(.Rows.Count, "BA").End(xlUp).Row
With rng.Parent
.Select
.Range(LastRow).Select
End With
LastRow = ActiveCell.FormulaR1C1 = "=R[-1]C+1"
Selection.Copy
ActiveSheet.Range(LastRow).Select
ActiveSheet.Paste

End With

Sheets.Add After:=Sheets(Sheets.Count)
Sheets(Sheets.Count).Name = LastRow

ActiveSheet.Range("A1").Select

End Sub

.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top