I have a combo box with a list of ID's that I use as a filter to copy the associated values from another sheet ("Extração") where I have the ID's and more information about them on several columns.
Here follows the code I used and it works fine.
The problem is that I may have values on my combo box list that sometimes are not on the other sheet, so when that happens I select the value from the list, run the macro, and it gives back an error.
What I would like the macro to do is to look for the value selected on the combo box on the other sheet and if it's not there to give back a messagem saying that there are no values for that selection and stop running the rest of the macro.
Is this possible?
[CODE]
Dim src As Worksheet
Dim tgt As Worksheet
Dim filterRange As Range
Dim copyRange As Range
Dim copyRange2 As Range
Dim copyRange3 As Range
Dim cutRange As Range
Dim removeRange As Range
Dim Lastrow As Long
Set src = ThisWorkbook.Sheets("Extração")
Set tgt = ThisWorkbook.Sheets("Top")
tgt.AutoFilterMode = False
Lastrow = tgt.Range("B" & tgt.Rows.Count).End(xlUp).Row
Set cutRange = tgt.Range("B20:D" & Lastrow)
cutRange.ClearContents
src.AutoFilterMode = False
Lastrow = src.Range("B" & src.Rows.Count).End(xlUp).Row
Set filterRange = src.Range("B9:N" & Lastrow)
Set copyRange = src.Range("E10:E" & Lastrow)
Set copyRange2 = src.Range("J10:J" & Lastrow)
Set copyRange3 = src.Range("N10:N" & Lastrow)
filterRange.AutoFilter Field:=1, Criteria1:=Me.ComboBox1.Value
copyRange.SpecialCells(xlCellTypeVisible).Copy
tgt.Range("B20").PasteSpecial xlPasteValues
copyRange2.SpecialCells(xlCellTypeVisible).Copy
tgt.Range("C20").PasteSpecial xlPasteValues
copyRange3.SpecialCells(xlCellTypeVisible).Copy
tgt.Range("D20").PasteSpecial xlPasteValues
filterRange.AutoFilter Field:=1
[CODE]
Bookmarks