<> vbNullString Then

keiserj

Board Regular
Joined
May 31, 2013
Messages
89
Having to trouble getting this code to work. Used all last year and now always running debug and I'm struggling to figure out why?




Code:
Private Sub CommandButton1_Click()Dim ws As Worksheet
Dim shtname As String
Dim codes As String


If Workbook.TextBox1.Text <> vbNullString Then
    MsgBox "Need SEQ# for Naming Tab", vbDefaultButton1
    


Application.ScreenUpdating = False
codes = TextBox2.Value


shtname = TextBox1.Value




On Error Resume Next
Set ws = ThisWorkbook.Sheets(ComboBox1.Value)
ws.Select


ws.Copy after:=Sheet11


ActiveSheet.Name = shtname


ActiveSheet.Rows("1:1").Select
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
ActiveSheet.Range("A1:L1").Select
With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlTop
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
        .MergeCells = False
        End With
        Selection.Merge
ActiveSheet.Range("A1:L1") = codes


On Error GoTo 0
End If
End Sub
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
change of machine, software change ?
 
Upvote 0
If you would change this
Code:
If Workbook.TextBox1.Text <> vbNullString Then
to this
(Change the "Sheet2" reference to the actual Sheet Name where the TextBox is located)
Code:
If Sheets("Sheet2").Shapes("TextBox 1").TextFrame.Characters.Text <> vbNullstring Then
Does that make a difference?
BTW, with the code as is you'll get your message when there is data in the TextBox. Is that correct?
 
Last edited:
Upvote 0
When i replace this code i get a run-time error. What this it to confirm text box 1 is not blank.

If you would change this
Code:
If Workbook.TextBox1.Text <> vbNullString Then
to this
(Change the "Sheet2" reference to the actual Sheet Name where the TextBox is located)
Code:
If Sheets("Sheet2").Shapes("TextBox 1").TextFrame.Characters.Text <> vbNullstring Then
Does that make a difference?
BTW, with the code as is you'll get your message when there is data in the TextBox. Is that correct?
 
Upvote 0
What error do you get & on what line?
 
Upvote 0
Run-time error '438' Object doesn't support this property or method

Code:
If Sheets("INDEX").Shapes("TextBox1").TextFrame.Characters.Text <> vbNullString Then
 
Upvote 0
I meant in relation to your code.
 
Upvote 0
When I debug its starts on this line.
Code:
If Sheets("INDEX").Shapes("TextBox1").TextFrame.Characters.Text <> vbNullString Then
and the original was
Code:
[COLOR=#333333]If Workbook.TextBox1.Text <> vbNullString Then[/COLOR]
 
Upvote 0
Is the textbox on a sheet or a userform?
Also what is Workbook referring to?
 
Upvote 0

Forum statistics

Threads
1,224,822
Messages
6,181,165
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top