<> 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
 

Some videos you may like

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December

mole999

Moderator
Joined
Oct 23, 2004
Messages
10,524
Office Version
  1. 2019
  2. 2016
  3. 2013
Platform
  1. Windows
change of machine, software change ?
 

jolivanes

Well-known Member
Joined
Sep 5, 2004
Messages
1,690
Office Version
  1. 2013
  2. 2007
Platform
  1. Windows
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:

keiserj

Board Regular
Joined
May 31, 2013
Messages
89
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?
 

keiserj

Board Regular
Joined
May 31, 2013
Messages
89

ADVERTISEMENT

NO -Software or machine changes
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
53,384
Office Version
  1. 365
Platform
  1. Windows
What error do you get & on what line?
 

keiserj

Board Regular
Joined
May 31, 2013
Messages
89

ADVERTISEMENT

Run-time error '438' Object doesn't support this property or method

Code:
If Sheets("INDEX").Shapes("TextBox1").TextFrame.Characters.Text <> vbNullString Then
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
53,384
Office Version
  1. 365
Platform
  1. Windows
I meant in relation to your code.
 

keiserj

Board Regular
Joined
May 31, 2013
Messages
89
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]
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
53,384
Office Version
  1. 365
Platform
  1. Windows
Is the textbox on a sheet or a userform?
Also what is Workbook referring to?
 

Watch MrExcel Video

Forum statistics

Threads
1,123,505
Messages
5,602,062
Members
414,498
Latest member
jordanmiller7890

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
Top