Solved

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

Posted on 2015-01-30
5
104 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Lately there has been a variety of news related to U.S. employment.  Stories about worker productivity, automobile and airline unions, low employment and foreign laborers have frequented the news.  Each story has good and bad attributes we might arg…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This video walks the viewer through the process of creating envelopes and labels, with multiple names and addresses. Navigate to the “Start Mail Merge” button in the Mailings tab: Follow the step-by-step process until asked to find the address doc…
This video walks the viewer through the process of creating Hyperlinks for the web and other documents. Select the "Insert" tab: Click "Hyperlink":  Type "http://" followed by a web address to reference a website or navigate to a document to ref…

808 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