restrict populating values into textbox based on combobox & condition

leap out

Active Member
Joined
Dec 4, 2020
Messages
271
Office Version
  1. 2016
  2. 2010
Hi experts
I need add condition to my code when I select item from combobox1 based on matching column D should populate values into textbox1 based on matching column I , but the populated values into textbox1 should be bigger or equal 1,000.00 .
this is my code
VBA Code:
Private Sub combobox1_Change()
Dim f As Range
  With Worksheets("bmn")
    Set f = .Columns(4).Find(combobox1.Value, , xlValues, xlWhole)
    If Not f Is Nothing Then
       Me.TextBox1.Value=.Cells(f.Row, "I") 
    End If
  End With
End Sub
any suggestion guys ?
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
How about:

VBA Code:
Private Sub combobox1_Change()
  Dim f As Range
  Me.TextBox1.Value = ""
  With Worksheets("bmn")
    Set f = .Columns(4).Find(combobox1.Value, , xlValues, xlWhole)
    If Not f Is Nothing Then
      If .Cells(f.Row, "I") >= 1000 Then
        Me.TextBox1.Value = .Cells(f.Row, "I")
      Else
        MsgBox "the populated values into textbox1 should be bigger or equal 1,000.00 "
      End If
    End If
  End With
End Sub
 
Upvote 0
Thanks and sorry I don't ask the question is very will . I want selecting the last value if the item is duplicated based on condition . for instance if I select item QW-100 and will repeate more than one time like

QW-100 =1,000.00
QW-100= 1,200.00
QW-100=10,000.00 then should show the last value into textbox = 10,000.00
 
Upvote 0
Try this:

VBA Code:
Private Sub combobox1_Change()
  Dim f As Range
  Me.TextBox1.Value = ""
  With Worksheets("bmn")
    Set f = .Range("D:D").Find(combobox1.Value, , xlValues, xlWhole, xlByRows, xlPrevious, False)
    If Not f Is Nothing Then
      Me.TextBox1.Value = .Cells(f.Row, "I")
    End If
  End With
End Sub
 
Upvote 0
no I want the condition . I try modifying your code , but doesn't work
should populate the last value >= 1000 for duplicates items.
VBA Code:
Private Sub combobox1_Change()
  Dim f As Range
  Me.TextBox1.Value = ""
  With Worksheets("bmn")
    Set f = .Range("D:D").Find(Combobox1.Value, , xlValues, xlWhole, xlByRows, xlPrevious, False)
     If .Cells(f.Row, "I") >= 1000 Then
        Me.TextBox1.Value = .Cells(f.Row, "I")
    End If
  End With
End Sub
 
Upvote 0
I think I already understood.
Try this:

VBA Code:
Private Sub combobox1_Change()
  Dim f As Range
  Dim i As Long
  
  Me.TextBox1.Value = ""
  If combobox1.ListIndex = -1 Then Exit Sub
  
  With Worksheets("bmn")
    For i = .Range("D" & Rows.Count).End(3).Row To 1 Step -1
      If .Range("D" & i).Value = combobox1.Value And .Range("I" & i).Value >= 1000 Then
        Me.TextBox1.Value = .Range("I" & i).Value
      End If
    Next
  End With
End Sub
 
Upvote 0
Sorry, one detail was missing:

Rich (BB code):
Private Sub combobox1_Change()
  Dim f As Range
  Dim i As Long
  
  Me.TextBox1.Value = ""
  If combobox1.ListIndex = -1 Then Exit Sub
  
  With Worksheets("bmn")
    For i = .Range("D" & Rows.Count).End(3).Row To 1 Step -1
      If .Range("D" & i).Value = combobox1.Value And .Range("I" & i).Value >= 1000 Then
        Me.TextBox1.Value = .Range("I" & i).Value
        Exit Sub
      End If
    Next
  End With
End Sub
 
Upvote 0
yes this is exactly what I want . just the message box can you add to the code ,pleas?
actually I like it as in orginal code .
 
Upvote 0
just the message box can you add to the code ,pleas?
ok, try this:

VBA Code:
Private Sub combobox1_Change()
  Dim f As Range
  Dim i As Long
  
  Me.TextBox1.Value = ""
  If combobox1.ListIndex = -1 Then Exit Sub
  
  With Worksheets("bmn")
    For i = .Range("D" & Rows.Count).End(3).Row To 1 Step -1
      If .Range("D" & i).Value = combobox1.Value And .Range("I" & i).Value >= 1000 Then
        Me.TextBox1.Value = .Range("I" & i).Value
        Exit For
      End If
    Next
  End With
  If TextBox1.Value = "" Then
    MsgBox "the populated values into textbox1 should be bigger or equal 1,000.00 "
  End If
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,214,651
Messages
6,120,739
Members
448,989
Latest member
mariah3

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