Solved

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

Posted on 2015-01-30
5
105 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 47

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

Easy, flexible multimedia distribution & control

Coming soon!  Ideal for large-scale A/V applications, ATEN's VM3200 Modular Matrix Switch is an all-in-one solution that simplifies video wall integration. Easily customize display layouts to see what you want, how you want it in 4k.

Question has a verified solution.

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

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Use Windows Task Scheduler to print a Word document weekly so your printer ink won't dry out.
This video shows and describes the main difference between both orientations in Microsoft Word. Viewers will understand when to use each orientation and how to get the most out of them.
An overview on how to enroll an hourly employee into the employee database and how to give them access into the clock in terminal.

730 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