Look for item in two columns vba

kelly mort

Well-known Member
Joined
Apr 10, 2017
Messages
2,169
Office Version
  1. 2016
Platform
  1. Windows
Hello,

I have yet another issue here with me.

Below is a code I am using to track the availability of an item under the "textbox enter evet".

It's working okay for now.

However, I am trying to also track the item when the textbox changes its contents. That is when I click my listbox to load the textboxes.

Since my case statement is pointing to the third textbox, anytime I click the listbox, only the case else statement is applied.

Because during the "freg2" change event, the "freg3" has not yet switched.


Is there a way I can look for the item from those two columns without using the case statement based on the challenges I have reviewed above?


Code:
Private fEnterValue,  fNameID,  fSName 
Private Sub freg2_Enter()
If freg3 <> "" Then fEnterValue = Trim(freg2.Text)
Select Case freg3.Text
    Case "X", "Y", "Z"
    For Each fSName In Sheet1.[AZ7:AZ407]
        If fSName = fEnterValue Then
            fNameID = fSName.Offset(0, -1)
            Exit For
        End If
    Next fSName
    
    Case Else
    For Each fSName In Sheet1.[C7:C407]
        If fSName = fEnterValue Then
            fNameID = fSName.Offset(0, -1)
            Exit For
        End If
    Next fSName
End Select
End Sub
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Without a demo workbook suitable for replicating your environment I can only suggest that you use the freg3 change event.

Bye
 
Upvote 0
Okay thanks .

It helped.

I actually used both the freg2 update event and listbox click event to track it and it's working cool for now.
 
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,250
Members
452,623
Latest member
Techenthusiast

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