?
Solved

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

Posted on 2015-01-30
5
Medium Priority
?
107 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 150 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 49

Assisted Solution

by:Martin Liss
Martin Liss earned 450 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

Optimum High-Definition Video Viewing and Control

The ATEN VM0404HA 4x4 4K HDMI Matrix Switch supports 4K resolutions of UHD (3840 x 2160) and DCI (4096 x 2160) with refresh rates of 30 Hz (4:4:4) and 60 Hz (4:2:0). It is ideal for applications where the routing of 4K digital signals is required.

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.
This article describes a serious pitfall that can happen when deleting shapes using VBA.
This video shows the viewer how to set up and create Footnotes in their document. Click on the References tab: Select "Insert Footnote": Type in desired text:
XMind Plus helps organize all details/aspects of any project from large to small in an orderly and concise manner. If you are working on a complex project, use this micro tutorial to show you how to make a basic flow chart. The software is free when…
Suggested Courses

801 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