Solved

Get value from a combobox 3th column and then filter a range with that value.

Posted on 2015-01-30
5
103 Views
Last Modified: 2016-02-11
Hey everybody,

I want to filter a range with the value from a combobox with a columncount of 4 and then the value from the 3th column. Here under is the code and I hope you can help me.

Set Wbthis = ActiveWorkbook
Set Wsthis = ActiveSheet
Set Wb = Workbooks.Open(strFolderD)
Set Wsd = Wb.Worksheets("database")

Dim Filter1 As string
Dim Filter2 As string
Set Filter1 = Cboreferentie.Column(0).Value
Set Filter2 = Cboreferentie.Column(3).Value

Set rng = Wsd.Range("A2:XFD1048576")
rng.CurrentRegion.AutoFilter 1, Filter1
rng.CurrentRegion.AutoFilter 2, Filter2
rng.CurrentRegion.SpecialCells(xlCellTypeVisible).EntireRow.Delete
rng.CurrentRegion.AutoFilter

Open in new window


Greetings,
Nick
0
Comment
Question by:omlaag
  • 3
5 Comments
 
LVL 28

Assisted Solution

by:omgang
omgang earned 50 total points
ID: 40580728
Combo boxes are indexed from 0
Set Filter1 = Cboreferentie.Column(0).Value  <---- this is referring to the first column
Set Filter2 = Cboreferentie.Column(3).Value  <---- this is referring to the fourth column

To refer to the third column use Column(2).Value

OM Gang
0
 

Author Comment

by:omlaag
ID: 40580921
Thank you for your answer I made a mistake I needed the 4th column but because of my code saying 3 I was confused. But I still got problems filtering I got an error "Variable is not defined" when I run the code. And then the part "Cboreferentie" is selected in this section "Set Filter1 = Cboreferentie.Column(0).Value". "Cboreferentie" is the name of the combobox. I hope you can help me with that.

Greetings,
Nick
0
 
LVL 46

Assisted Solution

by:Martin Liss
Martin Liss earned 150 total points
ID: 40581880
Add the missing Dims and remove the Sets in lines 15 and 16 as I did below .

Dim Wbthis As Workbook
Dim Wb As Workbook
Dim Wsthis As Worksheet
Dim Wsd As Worksheet
Dim strFolderD As String
Dim Rng As Range

Set Wbthis = ActiveWorkbook
Set Wsthis = ActiveSheet
Set Wb = Workbooks.Open(strFolderD)
Set Wsd = Wb.Worksheets("database")

Dim Filter1 As String
Dim Filter2 As String
Filter1 = Cboreferentie.Column(0).Value
Filter2 = Cboreferentie.Column(3).Value

Set Rng = Wsd.Range("A2:XFD1048576")
Rng.CurrentRegion.AutoFilter 1, Filter1
Rng.CurrentRegion.AutoFilter 2, Filter2
Rng.CurrentRegion.SpecialCells(xlCellTypeVisible).EntireRow.Delete
Rng.CurrentRegion.AutoFilter

Open in new window


If that works then you don't actually need the Filter1 and Filter2 variables.

Dim Wbthis As Workbook
Dim Wb As Workbook
Dim Wsthis As Worksheet
Dim Wsd As Worksheet
Dim strFolderD As String
Dim Rng As Range

Set Wbthis = ActiveWorkbook
Set Wsthis = ActiveSheet
Set Wb = Workbooks.Open(strFolderD)
Set Wsd = Wb.Worksheets("database")

Set Rng = Wsd.Range("A2:XFD1048576")
Rng.CurrentRegion.AutoFilter 1,  Cboreferentie.Column(0).Value
Rng.CurrentRegion.AutoFilter 2,  Cboreferentie.Column(3).Value
Rng.CurrentRegion.SpecialCells(xlCellTypeVisible).EntireRow.Delete
Rng.CurrentRegion.AutoFilter

Open in new window

0
 

Accepted Solution

by:
omlaag earned 0 total points
ID: 40582068
The problem is solved I needed this code for the filter to get the right value. With the column(0).value I kept keeping errors. So don't know what the problem was.

With dataophalen.Cboreferentie
Filter = .List(.ListIndex, 0)
End With

Thank you for the help,
0
 

Author Closing Comment

by:omlaag
ID: 40590657
I accepted my own solution because I still was getting errors, so I've been searching the internet for other options to get the value from a combobox and that worked.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Today companies are subjected to more-and-more data, and it won't stop any time soon.  But there are obvious opportunities for reducing data, particularly data duplicated among companies.
A high-level exploration of how our ever-increasing access to information has changed the way we do our jobs.
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question