Extract a dynamic list from a range in Excel based on specific criteria

Raghav Chamadiya

New Member
Joined
May 31, 2020
Messages
13
Office Version
  1. 2016
Platform
  1. Windows
I want to extract serial numbers(Column A) from a range of data based on the value of column P (Release status). So, if the status is pending I want to add the serial number in my list.
In the end I want to show this dynamic list in a listbox in userform, where he will be able to further interact with it. Hence I want this done through VBA instead of formulae.
Thanks a lot
MrExcel1.png
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Hi & welcome to MrExcel.
Will you just want the serial number in the listbox?
 
Upvote 0
In that case, how about
VBA Code:
Private Sub UserForm_Initialize()
   Dim Rng As Range
   Dim Ary As Variant
   
   With Sheets("Sheet1")
      Set Rng = .Range("A2", .Range("A" & Rows.Count).End(xlUp))
   End With
   Ary = Evaluate("transpose(if(" & Rng.Offset(, 15).Address(, , , 1) & "=""Pending""," & Rng.Resize(, 3).Address(, , , 1) & ",false))")
   Me.ListBox1.List = Filter(Ary, False, False)
End Sub
 
Upvote 0
I just made a very small change because I wanted to look up the data from a different file:
VBA Code:
Private Sub UserForm_Initialize()
   Dim Rng As Range
   Dim Ary As Variant
   
   Dim nwb As Workbook
   Set nwb = Workbooks.Open("C:\Users\CHAMARA2\Downloads\Planning Sheet\Database.xlsm")
   
   With nwb.Sheets("Sheet1")
      Set Rng = .Range("A2", .Range("A" & Rows.Count).End(xlUp))
   End With
   Ary = Evaluate("transpose(if(" & Rng.Offset(, 15).Address(, , , 1) & "=""Pending""," & Rng.Resize(, 3).Address(, , , 1) & ",false))")
   Me.ListBox1.List = Filter(Ary, False, False)
End Sub

The problem is when I launch the form it gives me a type mismatch error and just takes me to the form without exactly telling where the problem is.
 
Upvote 0
Not sure what happened there, but it should be
VBA Code:
Ary = Evaluate("transpose(if(" & Rng.Offset(, 15).Address(, , , 1) & "=""Pending""," & Rng.Address(, , , 1) & ",false))")
 
Upvote 0
VBA Code:
Set Rng = .Range("A2", .Range("A" & Rows.Count).End(xlUp))

@Fluff - Was there a reason to leave Rows.Count unqualified, or is it just a typo?
 
Upvote 0
Was there a reason to leave Rows.Count unqualified, or is it just a typo?
Unless your dealing with different workbooks there is no need to qualify it. And even then you only need to qualify it if one of the books is an "old style" xls file.
 
Upvote 0

Forum statistics

Threads
1,214,832
Messages
6,121,845
Members
449,051
Latest member
excelquestion515

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