ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Macro don’t work (https://www.excelbanter.com/excel-programming/423946-macro-don%92t-work.html)

K[_2_]

Macro don’t work
 
Hi all, I have macro (see below) which basically check for sheet name
if it already exists and if not then it copy the specified sheet to
last and name it. But I am getting error in macro below on line "If
ActiveWorkbook.Worksheets(Me.Range("B12").Value) Is Nothing Then".
Can please any friend tell what am i doing wrong.

Private Sub CommandButton1_Click()
If Me.Range("B12").Value = "" Then
MsgBox "ENTER FURTHER OBJECTIVE CODE", vbCritical, "NO FUROBJ ENTERED"
Else
If ActiveWorkbook.Worksheets(Me.Range("B12").Value) Is Nothing Then
Sheets("Exp & Inc Template").Copy after:=Sheets(Sheets.Count)
ActiveSheet.Name = Me.Range("B12").Value
ActiveSheet.Range("L1").Value = Me.Range("B12").Value
ActiveSheet.Range("A32").Select
Me.Range("B12:E17").ClearContents
Else
MsgBox "SHEET" & "* " & Me.Range("B12").Value & " *" & "ALREADY
EXIST", vbCritical, "ERROR"
End If
End If
End Sub

Bob Phillips[_3_]

Macro don't work
 
Private Sub CommandButton1_Click()
Dim FileLen As Long

If Me.Range("B12").Value = "" Then

MsgBox "ENTER FURTHER OBJECTIVE CODE", vbCritical, "NO FUROBJ
ENTERED"
Else

On Error Resume Next
FileLen = Len(ActiveWorkbook.Worksheets(Me.Range("B12").Valu e).Name)
On Error GoTo 0
If FileLen = 0 Then
Sheets("Exp & Inc Template").Copy after:=Sheets(Sheets.Count)
ActiveSheet.Name = Me.Range("B12").Value
ActiveSheet.Range("L1").Value = Me.Range("B12").Value
ActiveSheet.Range("A32").Select
Me.Range("B12:E17").ClearContents
Else
MsgBox "SHEET" & "* " & Me.Range("B12").Value & " *" & "ALREADY
EXIST", vbCritical, "ERROR"
End If
End If
End Sub



--
__________________________________
HTH

Bob

"K" wrote in message
...
Hi all, I have macro (see below) which basically check for sheet name
if it already exists and if not then it copy the specified sheet to
last and name it. But I am getting error in macro below on line "If
ActiveWorkbook.Worksheets(Me.Range("B12").Value) Is Nothing Then".
Can please any friend tell what am i doing wrong.

Private Sub CommandButton1_Click()
If Me.Range("B12").Value = "" Then
MsgBox "ENTER FURTHER OBJECTIVE CODE", vbCritical, "NO FUROBJ ENTERED"
Else
If ActiveWorkbook.Worksheets(Me.Range("B12").Value) Is Nothing Then
Sheets("Exp & Inc Template").Copy after:=Sheets(Sheets.Count)
ActiveSheet.Name = Me.Range("B12").Value
ActiveSheet.Range("L1").Value = Me.Range("B12").Value
ActiveSheet.Range("A32").Select
Me.Range("B12:E17").ClearContents
Else
MsgBox "SHEET" & "* " & Me.Range("B12").Value & " *" & "ALREADY
EXIST", vbCritical, "ERROR"
End If
End If
End Sub




K[_2_]

Macro don't work
 
On Feb 12, 10:17*am, "Bob Phillips" wrote:
Private Sub CommandButton1_Click()
Dim FileLen As Long

* * If Me.Range("B12").Value = "" Then

* * * * MsgBox "ENTER FURTHER OBJECTIVE CODE", vbCritical, "NO FUROBJ
ENTERED"
* * Else

* * * * On Error Resume Next
* * * * FileLen = Len(ActiveWorkbook.Worksheets(Me.Range("B12")..Val ue).Name)
* * * * On Error GoTo 0
* * * * If FileLen = 0 Then
* * * * * * Sheets("Exp & Inc Template").Copy after:=Sheets(Sheets.Count)
* * * * * * ActiveSheet.Name = Me.Range("B12").Value
* * * * * * ActiveSheet.Range("L1").Value = Me.Range("B12")..Value
* * * * * * ActiveSheet.Range("A32").Select
* * * * * * Me.Range("B12:E17").ClearContents
* * * * Else
* * * * * * MsgBox "SHEET" & "* " & Me.Range("B12").Value & " *" & "ALREADY
EXIST", vbCritical, "ERROR"
* * * * End If
* * End If
End Sub

--
__________________________________
HTH

Bob

"K" wrote in message

...



Hi all, *I have macro (see below) which basically check for sheet name
if it already exists and if not then it copy the specified sheet to
last and name it. *But I am getting error in macro below on line "If
ActiveWorkbook.Worksheets(Me.Range("B12").Value) Is Nothing Then".
Can please any friend tell what am i doing wrong.


Private Sub CommandButton1_Click()
If Me.Range("B12").Value = "" Then
MsgBox "ENTER FURTHER OBJECTIVE CODE", vbCritical, "NO FUROBJ ENTERED"
Else
If ActiveWorkbook.Worksheets(Me.Range("B12").Value) Is Nothing Then
Sheets("Exp & Inc Template").Copy after:=Sheets(Sheets.Count)
ActiveSheet.Name = Me.Range("B12").Value
ActiveSheet.Range("L1").Value = Me.Range("B12").Value
ActiveSheet.Range("A32").Select
Me.Range("B12:E17").ClearContents
Else
MsgBox "SHEET" & "* " & Me.Range("B12").Value & " *" & "ALREADY
EXIST", vbCritical, "ERROR"
End If
End If
End Sub- Hide quoted text -


- Show quoted text -


Thanks lot Bob

Chip Pearson

Macro don’t work
 
Try code like the following:

Sub AAA()
Dim WB As Workbook
Dim WS As Worksheet
Dim WSName As String
Set WB = ActiveWorkbook
WSName = Range("B12").Value
If WSName = vbNullString Then
MsgBox "Enter a sheet name in B12"
Exit Sub
End If
On Error Resume Next
Set WS = WB.Worksheets(WSName)
On Error GoTo 0
If WS Is Nothing Then
' sheet does not exist. create it
With WB.Worksheets
Set WS = .Add(after:=.Item(.Count))
End With
WS.Name = WSName
Else
' sheet already exists.
MsgBox "Sheet '" & WSName & "' already exists."
End If
End Sub

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)


On Thu, 12 Feb 2009 01:59:17 -0800 (PST), K
wrote:

Hi all, I have macro (see below) which basically check for sheet name
if it already exists and if not then it copy the specified sheet to
last and name it. But I am getting error in macro below on line "If
ActiveWorkbook.Worksheets(Me.Range("B12").Value ) Is Nothing Then".
Can please any friend tell what am i doing wrong.

Private Sub CommandButton1_Click()
If Me.Range("B12").Value = "" Then
MsgBox "ENTER FURTHER OBJECTIVE CODE", vbCritical, "NO FUROBJ ENTERED"
Else
If ActiveWorkbook.Worksheets(Me.Range("B12").Value) Is Nothing Then
Sheets("Exp & Inc Template").Copy after:=Sheets(Sheets.Count)
ActiveSheet.Name = Me.Range("B12").Value
ActiveSheet.Range("L1").Value = Me.Range("B12").Value
ActiveSheet.Range("A32").Select
Me.Range("B12:E17").ClearContents
Else
MsgBox "SHEET" & "* " & Me.Range("B12").Value & " *" & "ALREADY
EXIST", vbCritical, "ERROR"
End If
End If
End Sub


K[_2_]

Macro don’t work
 
On Feb 12, 3:16*pm, Chip Pearson wrote:
Try code like the following:

Sub AAA()
* * Dim WB As Workbook
* * Dim WS As Worksheet
* * Dim WSName As String
* * Set WB = ActiveWorkbook
* * WSName = Range("B12").Value
* * If WSName = vbNullString Then
* * * * MsgBox "Enter a sheet name in B12"
* * * * Exit Sub
* * End If
* * On Error Resume Next
* * Set WS = WB.Worksheets(WSName)
* * On Error GoTo 0
* * If WS Is Nothing Then
* * * * ' sheet does not exist. create it
* * * * With WB.Worksheets
* * * * * * Set WS = .Add(after:=.Item(.Count))
* * * * End With
* * * * WS.Name = WSName
* * Else
* * * * ' sheet already exists.
* * * * MsgBox "Sheet '" & WSName & "' already exists."
* * End If
End Sub

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
* * Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLCwww.cpearson.com
(email on web site)

On Thu, 12 Feb 2009 01:59:17 -0800 (PST), K
wrote:



Hi all, *I have macro (see below) which basically check for sheet name
if it already exists and if not then it copy the specified sheet to
last and name it. *But I am getting error in macro below on line "If
ActiveWorkbook.Worksheets(Me.Range("B12").Value ) Is Nothing Then".
Can please any friend tell what am i doing wrong.


Private Sub CommandButton1_Click()
If Me.Range("B12").Value = "" Then
MsgBox "ENTER FURTHER OBJECTIVE CODE", vbCritical, "NO FUROBJ ENTERED"
Else
If ActiveWorkbook.Worksheets(Me.Range("B12").Value) Is Nothing Then
Sheets("Exp & Inc Template").Copy after:=Sheets(Sheets.Count)
ActiveSheet.Name = Me.Range("B12").Value
ActiveSheet.Range("L1").Value = Me.Range("B12").Value
ActiveSheet.Range("A32").Select
Me.Range("B12:E17").ClearContents
Else
MsgBox "SHEET" & "* " & Me.Range("B12").Value & " *" & "ALREADY
EXIST", vbCritical, "ERROR"
End If
End If
End Sub- Hide quoted text -


- Show quoted text -


thanks chip it works greate


All times are GMT +1. The time now is 01:22 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com