Help re modify code to lood with separate controls

pimp_mentality

New Member
Joined
Oct 15, 2015
Messages
46
Good Day All

Hopefully this isn't a silly question as sometimes silly questions are ignored :LOL:

I use the following code to save data to my work sheet using only textboxes

Code:
Dim t As Control, res As VbMsgBoxResult, i As Long, TextBox As Control, z As ControlDim a As Long, b As Long
Dim x As Integer


a = Sheets("Student Info").Columns(1).Find(Reg1.Value, , , 1).Row
b = Sheets("Student Info").Cells(a, Columns.Count).End(xlToLeft).Column


For Each t In Me.Controls
    If TypeName(t) = "TextBox" Then
        If t.Text = vbNullString Then t.Text = ""
    End If
Next


For i = 4 To 320
    Sheets("Student Info").Cells(a, b + (i - 3)).Value = Me.Controls("TextBox" & i).Value
Next i


Unload Me

The issue is due to the nature of the userform and the data being inputed, a Userform which incoperates TextBoxes, ComboBoxes, Checkboxes and Optionbuttons would be much more ideal and effecient for my needs. As it is now the above code can only save only One control (hope i'm using the terminology right) i.e. TextBoxes.

I would appreciate assistance in modifying the above code (as needed) so that I can utilise TextBoxes, ComboBoxes as well as other controls and still accomodate the 300 plus comtrols (or more) as may be required.

The ususal consideration from forum members is most appreciated
 
Last edited:

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
I have been experimenting with just trying to incorporate textboxes and comboboxes with no success below is one of my experiments

Code:
[COLOR=#333333]Dim t As Control, res As VbMsgBoxResult, i As Long, TextBox As Control, z As ControlDim a As Long, b As Long[/COLOR]Dim x As Integer


a = Sheets("Student Info").Columns(1).Find(Reg1.Value, , , 1).Row
b = Sheets("Student Info").Cells(a, Columns.Count).End(xlToLeft).Column


For Each t In Me.Controls
    If TypeName(t) = "TextBox" or TypeName (t) = "ComboBox" Then
        If t.Text = vbNullString Then t.Text = ""
    End If
Next


For i = 4 To 320
    Sheets("Student Info").Cells(a, b + (i - 3)).Value = Me.Controls((t) & i).Value
Next i

 [COLOR=#333333]Unload Me[/COLOR]

I will still keep experimenting. Assistance is still welcomed though
 
Upvote 0

Forum statistics

Threads
1,215,509
Messages
6,125,215
Members
449,215
Latest member
texmansru47

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