Open userform upon entering data in cell

Bandito1

Board Regular
Joined
Oct 18, 2018
Messages
239
Office Version
  1. 2016
Platform
  1. Windows
Hi all,

I got this excel sheet named "Data Gel" where i add data into.

in column A is gel code (for example 1050). in column B is batch number (for example 308102).
In column E and F i note a "x" for when i return the batch. E is production returns and F is other returns.

Now i would like that a useform shows when i type a "x" in column E or F.
When this userform opens i would like that in textbox1 it shows the corresponding gel code and in textbox2 the batchnumber of that batch.

Anyone knows how i do this?
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Try this:

at TOP of STANDARD module (above all subs)
Code:
Public GelCode As String, BatchNumber As String

in SHEET module
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.CountLarge > 1 Then Exit Sub
    Dim c As Long: c = Target.Column
    If c = 5 Or c = 6 Then
        If LCase(Target) = "x" Then
            '[COLOR=#006400][I]get cell values[/I][/COLOR]
            GelCode = Cells(Target.Row, "A")
            BatchNumber = Cells(Target.Row, "B")
            
            UserForm1.Show
        End If
    End If
End Sub

in USERFORM module
Code:
Private Sub UserForm_Initialize()
[I][COLOR=#006400]'place values in textboxes[/COLOR][/I]
    TextBox1.Value = GelCode
    TextBox2.Value = BatchNumber

[I][COLOR=#006400]'clear variables[/COLOR][/I]
    GelCode = ""
    BatchNumber = ""
End Sub
 
Upvote 0
Try this:-
Code:
Private [COLOR="Navy"]Sub[/COLOR] Worksheet_Change(ByVal Target [COLOR="Navy"]As[/COLOR] Range)
[COLOR="Navy"]If[/COLOR] Target.Column = 5 Or Target.Column = 6 [COLOR="Navy"]Then[/COLOR]
  [COLOR="Navy"]If[/COLOR] Target.Value = "x" [COLOR="Navy"]Then[/COLOR]
    [COLOR="Navy"]With[/COLOR] UserForm1
     .TextBox1.Text = Cells(Target.Row, "A")
     .TextBox2.Text = Cells(Target.Row, "B")
     .Show
   [COLOR="Navy"]End[/COLOR] With
  [COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Last edited:
Upvote 0
Thank you both for your replies, both work perfectly!
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,463
Messages
6,178,818
Members
452,881
Latest member
motivationgyan

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