Edit for current working userform

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,251
Office Version
  1. 2007
Platform
  1. Windows
Afternoon,

I have a working userform which the code is shown here.

VBA Code:
Private Sub TransferButton_Click()
    Dim i As Integer
    Dim ControlsArr As Variant, ctrl As Variant
    Dim x As Long
    For i = 1 To 2
       With Me.Controls("ComboBox" & i)
            If .ListIndex = -1 Then
                MsgBox "MUST SELECT ALL OPTIONS", 48, "MONTH,YEAR & MILEAGE TRANSFER MESSAGE"
                .SetFocus
                Exit Sub
            End If
        End With
    Next i
    
    ControlsArr = Array(Me.ComboBox1, Me.ComboBox2)
    
    With ThisWorkbook.Worksheets("MILEAGE")
        For i = 0 To UBound(ControlsArr)
         Select Case i
            Case 1, 2, 4
               .Cells(1, i + 3) = IIf(IsNumeric(ControlsArr(i)), Val(ControlsArr(i)), ControlsArr(i))
            Case Else
               .Cells(1, i + 2) = ControlsArr(i)
               ControlsArr(i).Text = ""
         End Select
    Next i

    End With
    
    ActiveWorkbook.Save
    Application.ScreenUpdating = True
    
    MsgBox "Month,Year & Mileage Have Been Updated", vbInformation, "SUCCESSFUL MILEAGE MESSAGE"
    Unload MYFMILEAGE
End Sub

I have now added the TextBox1 to the userform as shown in photo supplied.
When i type a value in the TextBox once the command button is pressed this value should be entered in cell A34

Can you advise please how i edit the code so both comboboxes & textbox must be complete where at present its just set up for combobox.
Also how we send the value to cell A34

Many thansk & have a nice day
 

Attachments

  • 6231.jpg
    6231.jpg
    72.3 KB · Views: 5

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
How is this code written correctly please.

VBA Code:
    For i = 1 To 3
       With Me.Controls("ComboBox", "TextBox1" & i)

Ive changed the 1 To 2 for 1 To 3

The userform has 2 ComboBoxes & 1 TextBox1
Hence my attempt at the second line but it gives me the run time error screenshot
 

Attachments

  • 6232.jpg
    6232.jpg
    27.7 KB · Views: 2
Upvote 0
Any advice please for how to edit post #1
TextBox1 was added to the form in question.

Thanks
 
Upvote 0

Forum statistics

Threads
1,215,765
Messages
6,126,753
Members
449,336
Latest member
p17tootie

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