Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Add worksheet based on textbox/userform

Hello world

I have some code from Chip Pearson (Posted here!) but I need some help with
it. Basically a userform is asking a user to input information relating to
pallets. The form is asking the user to tell it what the pallet number is
where goods are being added to. The code works great but what I don't
understand is how to stop sheets(no.) being added when a duplicate is
found...

Private Sub Text4_Change()
Dim ans As String
ans = Text4.Text 'InputBox("What is the pallet number?", "Pallet
Number")
If ThisWorkbook.SheetExists(ans) = False Then
Sheets.Add.Name = ans
Worksheets.Add after:=Worksheets(Worksheets.Count)
Sheets(ans).Select
Else
MsgBox "Error: Pallet " & ans & " aleady exists.", vbInformation
Exit Sub
End If
'OrderNo.Show
End Sub

Function SheetExists(sname As String, _
Optional ByVal WB As Workbook) As Boolean
'Chip Pearson
On Error Resume Next
If WB Is Nothing Then Set WB = ThisWorkbook
SheetExists = CBool(Len(WB.Sheets(sname).Name))
End Function

Any help as always appreciated
Mark (InWales)


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,173
Default Add worksheet based on textbox/userform

Mark

Only lightly tested...but this should work

Private Sub Text4_Change()
Dim ans As String
Dim wks As Worksheet
ans = Text4.Text 'InputBox("What is the pallet number?", "Pallet Number ")"
For Each wks In ThisWorkbook.Worksheets
If wks.Name = ans Then
MsgBox "Error: Pallet " & ans & " already exists.", vbOKOnly +
vbInformation
Exit Sub
End If
Next wks
Sheets.Add.Name = ans
Worksheets.Add after:=Worksheets(Worksheets.Count)
Sheets(ans).Select
'OrderNo.Show
End Sub

--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
HIS


"Mark (InWales)" wrote in message
...
Hello world

I have some code from Chip Pearson (Posted here!) but I need some help
with it. Basically a userform is asking a user to input information
relating to pallets. The form is asking the user to tell it what the
pallet number is where goods are being added to. The code works great but
what I don't understand is how to stop sheets(no.) being added when a
duplicate is found...

Private Sub Text4_Change()
Dim ans As String
ans = Text4.Text 'InputBox("What is the pallet number?", "Pallet
Number")
If ThisWorkbook.SheetExists(ans) = False Then
Sheets.Add.Name = ans
Worksheets.Add after:=Worksheets(Worksheets.Count)
Sheets(ans).Select
Else
MsgBox "Error: Pallet " & ans & " aleady exists.", vbInformation
Exit Sub
End If
'OrderNo.Show
End Sub

Function SheetExists(sname As String, _
Optional ByVal WB As Workbook) As Boolean
'Chip Pearson
On Error Resume Next
If WB Is Nothing Then Set WB = ThisWorkbook
SheetExists = CBool(Len(WB.Sheets(sname).Name))
End Function

Any help as always appreciated
Mark (InWales)



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Add worksheet based on textbox/userform

That's marvellous. Thank you very much Nick for your help

Mark (InWales)

"Nick Hodge" wrote in message
...
Mark

Only lightly tested...but this should work

Private Sub Text4_Change()
Dim ans As String
Dim wks As Worksheet
ans = Text4.Text 'InputBox("What is the pallet number?", "Pallet Number
")"
For Each wks In ThisWorkbook.Worksheets
If wks.Name = ans Then
MsgBox "Error: Pallet " & ans & " already exists.", vbOKOnly +
vbInformation
Exit Sub
End If
Next wks
Sheets.Add.Name = ans
Worksheets.Add after:=Worksheets(Worksheets.Count)
Sheets(ans).Select
'OrderNo.Show
End Sub

--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
HIS


"Mark (InWales)" wrote in message
...
Hello world

I have some code from Chip Pearson (Posted here!) but I need some help
with it. Basically a userform is asking a user to input information
relating to pallets. The form is asking the user to tell it what the
pallet number is where goods are being added to. The code works great
but what I don't understand is how to stop sheets(no.) being added when a
duplicate is found...

Private Sub Text4_Change()
Dim ans As String
ans = Text4.Text 'InputBox("What is the pallet number?", "Pallet
Number")
If ThisWorkbook.SheetExists(ans) = False Then
Sheets.Add.Name = ans
Worksheets.Add after:=Worksheets(Worksheets.Count)
Sheets(ans).Select
Else
MsgBox "Error: Pallet " & ans & " aleady exists.", vbInformation
Exit Sub
End If
'OrderNo.Show
End Sub

Function SheetExists(sname As String, _
Optional ByVal WB As Workbook) As Boolean
'Chip Pearson
On Error Resume Next
If WB Is Nothing Then Set WB = ThisWorkbook
SheetExists = CBool(Len(WB.Sheets(sname).Name))
End Function

Any help as always appreciated
Mark (InWales)





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calculate Textbox value based on another textbox value.doc Tdungate Excel Discussion (Misc queries) 1 February 12th 09 07:11 PM
Calculate Textbox value based on another textbox value Tdungate Excel Discussion (Misc queries) 0 February 12th 09 07:03 PM
Generating a Userform based on a worksheet Glenn Excel Discussion (Misc queries) 0 March 4th 05 07:25 PM
Textbox in userform Harald Staff Excel Programming 0 September 8th 04 11:51 AM
UserForm TextBox to ActiveSheet TextBox over 256 characters Dan E[_2_] Excel Programming 1 July 28th 03 07:36 PM


All times are GMT +1. The time now is 05:42 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"