bbarrene
asked on
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?
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
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
wks.Cells(Cells.Rows.Count
Columns(ColumnLetter).Colu
to
Set NextCell = Range(wks.Cells(Cells.Rows
Columns(ColumnLetter).Colu
HTH
Ivo Stoykov