VBA Loop Search

raccoon588

Board Regular
Joined
Aug 5, 2016
Messages
118
The code bellow goes through my list of NAEDs and if the NAED is on the list it should activate combo boxes if the NAED is not in the list it should not activate the boxes. once this code finds a partial match it makes the combo boxes available i do not want that. It has to match the NAED in the list exactly in order for the combo boxes to be made available. what can i do to fix this?



Code:
Private Sub CmbNAED_Change()

Dim r As Long, LastRows As Long, wss As Worksheet
Set wss = Sheets("Data")
LastRows = wss.Range("D" & Rows.Count).End(xlUp).Row


For r = 2 To LastRows
If Val(Me.CmbNAED.Value) = wss.Cells(r, "D") Then
Me.CmbSealing.Enabled = True
Me.CmbSealing.Value = ""
Me.CmbVaccum.Enabled = True
Me.CmbVaccum.Value = ""
End If
Next r
end sub
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Hi,
untested but see if this update does what you want

Code:
Private Sub CmbNAED_Change()
    Dim m As Variant, arr As Variant
    Dim LastRows As Long
    Dim wss As Worksheet
    
    Set wss = Sheets("Data")
    LastRows = wss.Range("D" & wss.Rows.Count).End(xlUp).Row
    
    arr = wss.Cells(1, "D").Resize(LastRows, 1).Value2
    
    m = Application.Match(Val(Me.CmbNAED.Value), arr, 0)
    
    With Me.CmbSealing
        .Enabled = CBool(Not IsError(m))
    If Not .Enabled Then .Value = ""
    End With
    
    With Me.CmbVaccum
        .Enabled = CBool(Not IsError(m))
    If Not .Enabled Then .Value = ""
    End With
End Sub

Dave
 
Upvote 0

Forum statistics

Threads
1,223,711
Messages
6,174,025
Members
452,542
Latest member
Bricklin

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