Solved

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

Posted on 2015-01-30
5
98 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
Comment Utility
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
Comment Utility
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 45

Assisted Solution

by:Martin Liss
Martin Liss earned 150 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This article describes how to use the Send to Mail Recipient command. The instructions apply generally to Office 2007 and later versions, but Microsoft® Word 2013 was used for the specific steps and figures.  What is Send to Mail Recipient? Send…
With the internet and the ease of information transference, many professional jobs can be done anywhere today.  Why should it make a difference whether an x-ray is read in India or the United States as long as the radiologist is qualified?   Outso…
This video walks the viewer through the process of creating a watermark for their document, customizing it, and saving it for viewing/printing needs.
The viewer will learn how to make their project stand out over others by learning how to change colors and shapes, add spaces, change directions, and add bullets to their charts.

744 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now