Need help with userform vba

johnsonk

Board Regular
Joined
Feb 4, 2019
Messages
172
Hi I have a UserForm with option buttons combobox and textboxes at the moment it is used for booking in and I have added another option button to book out and I need it to deduct the value, see link below to see how it works.

[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]https://www.dropbox.com/s/m95u5skdxnjgj0x/TESTER1.xlsb?dl=0[/FONT]
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
I have tried but can not get it to work.

Always worth sharing what you have tried

Rich (BB code):
Private Sub CommandButton1_Click()
    Dim NewRow As Long
    Dim m As Variant
    
    Application.DisplayAlerts = False
    
    With wsIngData
        NewRow = .Range("A" & .Rows.count).End(xlUp).Row + 1
        .Range("B" & NewRow).Value = Me.TextBox1.Text
        .Range("I" & NewRow).Value = Me.TextBox2.Text
        .Range("C" & NewRow).Value = Me.TextBox3.Text
        .Range("D" & NewRow).Value = Me.TextBox4.Text
        .Range("E" & NewRow).Value = Me.TextBox5.Text
        .Range("F" & NewRow).Value = Me.TextBox6.Text
        .Range("H" & NewRow).Value = Me.TextBox7.Text
        .Range("A" & NewRow).Value = Me.ComboBox1.Text
        .Range("J" & NewRow).Value = IIf(Me.opt_In.Value, "IN", "OUT")
        .Range("G" & NewRow).Value = Me.DTPicker1.Value
        .Range("K" & NewRow).Value = Now
    
    End With
'update master
    With wsIngMaster
        m = Application.Match(Val(Me.ComboBox1.Text), .Columns(1), 0)
        If Not IsError(m) Then
        With .Cells(CLng(m), "D")
            If Me.opt_In Then
                  .Value = .Value + Val(Me.TextBox5.Value)
               ElseIf Me.opt_Out Then
                  .Value = .Value - Val(Me.TextBox5.Value)
               End If
            End With
        End If
    End With
    opt_In.Value = False
    Application.DisplayAlerts = True
    Unload Me
End Sub


I have added changes Fluff suggested in your other post for similar requirement - see if this does what you want

As an aside, you may also want to change the caption of the CommandButton to reflect the activity selected with your OptionButton

Rich (BB code):
Private Sub opt_In_Click()
Me.CommandButton1.Caption = "Book In"
End Sub


Private Sub opt_Out_Click()
Me.CommandButton1.Caption = "Book Out"
End Sub

Dave
 
Upvote 0
dmt32 that works perfect thank you i just had to take one line out at the very end opt_In.value = True as it was causing an error
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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