Open userform upon entering data in cell

Bandito1

Board Regular
Joined
Oct 18, 2018
Messages
82
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?
 

Yongle

Well-known Member
Joined
Mar 11, 2015
Messages
4,672
Office Version
365
Platform
Windows
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
 

MickG

MrExcel MVP
Joined
Jan 9, 2008
Messages
14,841
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:

Bandito1

Board Regular
Joined
Oct 18, 2018
Messages
82
Thank you both for your replies, both work perfectly!
 
Last edited:

Forum statistics

Threads
1,082,132
Messages
5,363,340
Members
400,728
Latest member
Hoan1985

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top