CavanHomewoodInstall
New Member
- Joined
- Mar 11, 2021
- Messages
- 7
- Office Version
- 365
- 2019
- 2016
- Platform
- Windows
- MacOS
- Mobile
- Web
Hello everyone,
I want VBA to look up cell A46 and set the name. This is the code I currently have.
Sub Rectangle2_Click()
ActiveSheet.Copy after:=Sheets(Sheets.Count)
Sheets(Sheets.Count).Name = GetName
End Sub
Private Function GetName() As String
Dim x As Long, n As String
n = "JJJJ "
If SheetExists Then
Do
x = x + 1
If Not SheetExists(n & x) Then Exit Do
Loop
n = n & x
End If
GetName = n
End Function
Private Function SheetExists(aName As String) As Boolean
On Error Resume Next
Dim sh As Worksheet: Set sh = Sheets(aName)
If Err = 0 Then SheetExists = True Else SheetExists = False
End Function
I want VBA to look up cell A46 and set the name. This is the code I currently have.
Sub Rectangle2_Click()
ActiveSheet.Copy after:=Sheets(Sheets.Count)
Sheets(Sheets.Count).Name = GetName
End Sub
Private Function GetName() As String
Dim x As Long, n As String
n = "JJJJ "
If SheetExists Then
Do
x = x + 1
If Not SheetExists(n & x) Then Exit Do
Loop
n = n & x
End If
GetName = n
End Function
Private Function SheetExists(aName As String) As Boolean
On Error Resume Next
Dim sh As Worksheet: Set sh = Sheets(aName)
If Err = 0 Then SheetExists = True Else SheetExists = False
End Function