Assigning Variables to Control TextBox and Column

I have a workbook that has similar worksheets for different categories (Part Type, Vendor, Machine, Station, etc.) to enter new entries.

I am trying to create a Sub that could be used by all of the worksheets when a "Submit" button is pressed within each worksheet. The "Submit" button is a Control Button (not a Form Button). When the button is pressed, the text in the Control Textbook of the worksheet, where the button was pressed, is copied to the next available cell within the specified column of the worksheet.

I am using different names for each textbox in each worksheet because I do not believe I can name them all the same Name. Also, the column to insert the text from the textbox varies as well. I get errors when I assign variables to the Textbox and Column. Does anyone know what I am doing wrong?
Public wks As Worksheet
Public CopyTextBox As TextBox
Public NextCell As Range
Public ColumnLetter As String

'Code in Module
Sub SubmitEntry()
     
    Set NextCell = wks.Cells(Cells.Rows.Count, _
                    Columns(ColumnLetter).Column).End(xlUp).Offset(1, 0)
         
    NextCell.Value = CopyTextBox.Value
    CopyTextBox.Value = ""
    
End Sub

'Code in Part_Type Worksheet
Private Sub SubmitPartTypeButton()
    Set wks = Worksheets("Part_Type")
    Set CopyTextBox = wks.SubmitPartTypeTextbox 'Control Textbox Name in Sheet
    Set ColumnLetter = "D"
    Call SubmitEntry
End Sub

'Code in Vendor Worksheet
Private Sub SubmitVendorButton()
    Set wks = Worksheets("Vendor")
    Set CopyTextBox = wks.SubmitVendorTextbox 'Control Textbox Name in Sheet
    Set ColumnLetter = "E"
    Call SubmitEntry
End Sub

'Code in Machine Worksheet
Private Sub SubmitMachineButton()
    Set wks = Worksheets("Machine")
    Set CopyTextBox = wks.SubmitMachineTextbox 'Control Textbox Name in Sheet
    Set ColumnLetter = "B"
    Call SubmitEntry
End Sub

Open in new window

bbarreneAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ivo StoykovCommented:
change
 wks.Cells(Cells.Rows.Count, _
                    Columns(ColumnLetter).Column).End(xlUp).Offset(1, 0)

to

Set NextCell = Range(wks.Cells(Cells.Rows.Count, _
                    Columns(ColumnLetter).Column).End(xlUp).Offset(1, 0).Address)

HTH

Ivo Stoykov

0
RichardSchollarCommented:
Hi

Unless you're mixing and matching Forms controls and Controls Toolbox controls, you don't have a Textbox, you have an MSForms.Textbox so i expect you get a type mismatch when you try to run this code.


Public CopyTextBox As MSForms.TextBox

Richard
0
Rory ArchibaldCommented:
You don't need those control variables at all - just pass the value, worksheet and column to the sub directly:

'Code in Module
Sub SubmitEntry(varValue, wks as worksheet, strColumn as string)
     
    wks.Cells(wks.Rows.Count, _
                    strColumn).End(xlUp).Offset(1, 0).Value = varValue
    
End Sub

'Code in Part_Type Worksheet
Private Sub SubmitPartTypeButton()
    SubmitEntry Me.SubmitPartTypeTextbox.Value, Me, "D"
End Sub

'Code in Vendor Worksheet
Private Sub SubmitVendorButton()
    SubmitEntry Me.SubmitVendorTextbox.Value, Me, "E"
End Sub

'Code in Machine Worksheet
Private Sub SubmitMachineButton()
    SubmitEntry Me.SubmitMachineTextbox.Value, Me, "B"
End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.