Selecting variables based on values

alion

New Member
Joined
Aug 4, 2011
Messages
19
So I have some variables and their values like this:

AV1 2.3
AV2 1.2
AV3 3.0
AV4 3.1
AV5 2.5

Now if I want VBA to show me stocks with values between 2 and 3, it should give me AV1, AV3 and AV5 considering 3.0 was inclusive. How to do this? any clues?

thanks in advance
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
So I have some variables and their values like this:

AV1 2.3
AV2 1.2
AV3 3.0
AV4 3.1
AV5 2.5

Now if I want VBA to show me stocks with values between 2 and 3, it should give me AV1, AV3 and AV5 considering 3.0 was inclusive. How to do this? any clues?

thanks in advance

Not sure if this helps, but if the list of variables are in Columns A and B maybe this?

Code:
Sub Alion()
Dim lr As Long
Dim lr2 As Long

lr = Cells(Rows.Count, 1).End(3).Row



With Range("C1:C" & lr)

    .Formula = "=IF(AND(B1>2,B1<=3),A1,"""")"
    .Value = .Value
    .AutoFilter
    .AutoFilter Field:=1, Criteria1:="<>"
    .SpecialCells(xlCellTypeVisible).Copy Range("X1")
    .AutoFilter
    
End With

lr2 = Cells(Rows.Count, 24).End(3).Row

MsgBox Join(WorksheetFunction.Transpose(Range("X1:X" & lr2)), vbLf)

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,527
Messages
6,179,348
Members
452,907
Latest member
Roland Deschain

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