PC Review


Reply
Thread Tools Rate Thread

Autofilter and Listbox how to acomplish?

 
 
jose luis
Guest
Posts: n/a
 
      22nd Jun 2005

Hi,

I have a worksheet with data (7 columns, almost 200 rows). I would like
to see the results of an Autofilter operation in this worksheet to be
"reflected" on a Listbox at another wksheet. The listbox is form Active
Control, but could be changed to a Listbox from Forms. Wich one is
better o easier to implemment? Could you give some direction on how to
procced?


Thank you in advance,

Regards

Jose Luis


--
jose luis
------------------------------------------------------------------------
jose luis's Profile: http://www.excelforum.com/member.php...o&userid=13312
View this thread: http://www.excelforum.com/showthread...hreadid=381432

 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      23rd Jun 2005
I used the listbox from the control toolbox toolbar (ActiveX controls) and put
it on sheet1.

Then I used this code behind the worksheet.

Option Explicit
Private Sub Worksheet_Activate()

Dim wks As Worksheet
Dim rng As Range
Dim rngF As Range
Dim myCell As Range
Dim iCtr As Long

Set wks = Worksheets("sheet2")
Set rng = wks.AutoFilter.Range

With rng
Set rngF = .Resize(.Rows.Count - 1, 1).Offset(1, 0) _
.Cells.SpecialCells(xlCellTypeVisible)
End With

With Me.ListBox1
.Clear
.ColumnCount = rng.Columns.Count
For Each myCell In rngF.Cells
.AddItem (myCell.Value)
For iCtr = 1 To rng.Columns.Count - 1
.List(.ListCount - 1, iCtr) = myCell.Offset(0, iCtr).Value
Next iCtr
Next myCell
End With

End Sub

If you filter the data on sheet2, then go back (and activate sheet1), the
listbox gets updated.

jose luis wrote:
>
> Hi,
>
> I have a worksheet with data (7 columns, almost 200 rows). I would like
> to see the results of an Autofilter operation in this worksheet to be
> "reflected" on a Listbox at another wksheet. The listbox is form Active
> Control, but could be changed to a Listbox from Forms. Wich one is
> better o easier to implemment? Could you give some direction on how to
> procced?
>
> Thank you in advance,
>
> Regards
>
> Jose Luis
>
> --
> jose luis
> ------------------------------------------------------------------------
> jose luis's Profile: http://www.excelforum.com/member.php...o&userid=13312
> View this thread: http://www.excelforum.com/showthread...hreadid=381432


--

Dave Peterson
 
Reply With Quote
 
jose luis
Guest
Posts: n/a
 
      26th Jun 2005

Thank you Dave,

I ve tried your recommendation, unfortunately I can't make ru
smoothly. It post a message telling me "Automation error" "Unspecifie
error" "Permission Denied"
in the line


Code
-------------------
"With Me.ListBox1
.Clea
-------------------


Besides, Could you explain me what is the function of:


Code
-------------------
With rng
Set rngF = .Resize(.Rows.Count - 1, 1).Offset(1, 0).Cells.SpecialCells(xlCellTypeVisible)
End Wit
-------------------


I'm trying to fully understand your post to implemment you
recomendation,

Thanks again for your time and knowledge!

Jose Luis

Dave Peterson Wrote:
> I used the listbox from the control toolbox toolbar (ActiveX controls
> and put
> it on sheet1.
>
> Then I used this code behind the worksheet.
>
> Option Explicit
> Private Sub Worksheet_Activate()
>
> Dim wks As Worksheet
> Dim rng As Range
> Dim rngF As Range
> Dim myCell As Range
> Dim iCtr As Long
>
> Set wks = Worksheets("sheet2")
> Set rng = wks.AutoFilter.Range
>
> With rng
> Set rngF = .Resize(.Rows.Count - 1, 1).Offset(1, 0) _
> .Cells.SpecialCells(xlCellTypeVisible)
> End With
>
> With Me.ListBox1
> .Clear
> .ColumnCount = rng.Columns.Count
> For Each myCell In rngF.Cells
> .AddItem (myCell.Value)
> For iCtr = 1 To rng.Columns.Count - 1
> .List(.ListCount - 1, iCtr) = myCell.Offset(0, iCtr).Value
> Next iCtr
> Next myCell
> End With
>
> End Sub
>
> If you filter the data on sheet2, then go back (and activate sheet1)
> the
> listbox gets updated.
>
> jose luis wrote:
> >
> > Hi,
> >
> > I have a worksheet with data (7 columns, almost 200 rows). I woul

> like
> > to see the results of an Autofilter operation in this worksheet t

> be
> > "reflected" on a Listbox at another wksheet. The listbox is for

> Active
> > Control, but could be changed to a Listbox from Forms. Wich one is
> > better o easier to implemment? Could you give some direction on ho

> to
> > procced?
> >
> > Thank you in advance,
> >
> > Regards
> >
> > Jose Luis
> >
> > --
> > jose luis

>
> ------------------------------------------------------------------------
> > jose luis's Profile

> http://www.excelforum.com/member.php...o&userid=13312
> > View this thread

> http://www.excelforum.com/showthread...hreadid=381432
>
> --
>
> Dave Peterso


--
jose lui
-----------------------------------------------------------------------
jose luis's Profile: http://www.excelforum.com/member.php...fo&userid=1331
View this thread: http://www.excelforum.com/showthread.php?threadid=38143

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      26th Jun 2005
My bet is you assigned the .listfillrange to a range on one of those worksheets.

You can either change the .listfillrange property to nothing manually or in
code:

With Me.ListBox1
.ListFillRange = ""
.Clear

....

==========
Set rng = wks.AutoFilter.Range

With rng
Set rngF = .Resize(.Rows.Count - 1, 1).Offset(1, 0) _
.Cells.SpecialCells(xlCellTypeVisible)
End With

Rng represents the autofilter range on your worksheet.

the "with rng" means that everything that begins with a dot will refer to rng
while you're in that

With rng
....
end wigh
structure.


rng.rows.count -1 just finds the number of rows in the autofilter range and
subtracts 1.

So if you filtered A1:C100 (100 rows), rng.rows.count -1 will give 99 (rows).

The .resize() portion means to take the size of the autofilter rng (100 rows by
3 columns in my example) and change it to 99 rows by 1 column
".Resize(.Rows.Count - 1, 1)".

But just resizing it would mean that we're looking at A1:A99. So we come down
one row and over 0 columns (.offset(1,0)).

So now the example will point at A2:A100.

The .cells.specialcells(xlcelltypevisible) means to just use the visible cells
in that column.






jose luis wrote:
>
> Thank you Dave,
>
> I ve tried your recommendation, unfortunately I can't make run
> smoothly. It post a message telling me "Automation error" "Unspecified
> error" "Permission Denied"
> in the line
>
> Code:
> --------------------
> "With Me.ListBox1
> .Clear
> --------------------
>
> Besides, Could you explain me what is the function of:
>
> Code:
> --------------------
> With rng
> Set rngF = .Resize(.Rows.Count - 1, 1).Offset(1, 0).Cells.SpecialCells(xlCellTypeVisible)
> End With
> --------------------
>
> I'm trying to fully understand your post to implemment your
> recomendation,
>
> Thanks again for your time and knowledge!
>
> Jose Luis
>
> Dave Peterson Wrote:
> > I used the listbox from the control toolbox toolbar (ActiveX controls)
> > and put
> > it on sheet1.
> >
> > Then I used this code behind the worksheet.
> >
> > Option Explicit
> > Private Sub Worksheet_Activate()
> >
> > Dim wks As Worksheet
> > Dim rng As Range
> > Dim rngF As Range
> > Dim myCell As Range
> > Dim iCtr As Long
> >
> > Set wks = Worksheets("sheet2")
> > Set rng = wks.AutoFilter.Range
> >
> > With rng
> > Set rngF = .Resize(.Rows.Count - 1, 1).Offset(1, 0) _
> > .Cells.SpecialCells(xlCellTypeVisible)
> > End With
> >
> > With Me.ListBox1
> > .Clear
> > .ColumnCount = rng.Columns.Count
> > For Each myCell In rngF.Cells
> > .AddItem (myCell.Value)
> > For iCtr = 1 To rng.Columns.Count - 1
> > .List(.ListCount - 1, iCtr) = myCell.Offset(0, iCtr).Value
> > Next iCtr
> > Next myCell
> > End With
> >
> > End Sub
> >
> > If you filter the data on sheet2, then go back (and activate sheet1),
> > the
> > listbox gets updated.
> >
> > jose luis wrote:
> > >
> > > Hi,
> > >
> > > I have a worksheet with data (7 columns, almost 200 rows). I would

> > like
> > > to see the results of an Autofilter operation in this worksheet to

> > be
> > > "reflected" on a Listbox at another wksheet. The listbox is form

> > Active
> > > Control, but could be changed to a Listbox from Forms. Wich one is
> > > better o easier to implemment? Could you give some direction on how

> > to
> > > procced?
> > >
> > > Thank you in advance,
> > >
> > > Regards
> > >
> > > Jose Luis
> > >
> > > --
> > > jose luis
> > >

> > ------------------------------------------------------------------------
> > > jose luis's Profile:

> > http://www.excelforum.com/member.php...o&userid=13312
> > > View this thread:

> > http://www.excelforum.com/showthread...hreadid=381432
> >
> > --
> >
> > Dave Peterson

>
> --
> jose luis
> ------------------------------------------------------------------------
> jose luis's Profile: http://www.excelforum.com/member.php...o&userid=13312
> View this thread: http://www.excelforum.com/showthread...hreadid=381432


--

Dave Peterson
 
Reply With Quote
 
jose luis
Guest
Posts: n/a
 
      27th Jun 2005

Thanks Again Dave , Now the application is running smoothly. And I think
i understood in a better way your code. Just to finish, could you guide
me to format the last "field" in the ListBox? I wrote this but is not
working:



Code:
--------------------
With Sheets(1).ListBox1
.ListFillRange = ""
.Clear
.ColumnCount = rng.Columns.Count
For Each myCell In rngF.Cells
.AddItem (myCell.Value)
For iCtr = 1 To rng.Columns.Count - 1
if iCtr = 6 then
.List(.ListCount - 1, iCtr) = Format(myCell.Offset(0, iCtr).Value,"#,##0.#0")
else
.List(.ListCount - 1, iCtr) = myCell.Offset(0, iCtr).Value
end if
Next iCtr
Next myCell
End With
--------------------


Thank you very much for your help.

Regards

Jose Luis


Dave Peterson Wrote:
> My bet is you assigned the .listfillrange to a range on one of those
> worksheets.
>
> You can either change the .listfillrange property to nothing manually
> or in
> code:
>
> With Me.ListBox1
> .ListFillRange = ""
> .Clear
>
> ....
>
> ==========
> Set rng = wks.AutoFilter.Range
>
> With rng
> Set rngF = .Resize(.Rows.Count - 1, 1).Offset(1, 0) _
> .Cells.SpecialCells(xlCellTypeVisible)
> End With
>
> Rng represents the autofilter range on your worksheet.
>
> the "with rng" means that everything that begins with a dot will refer
> to rng
> while you're in that
>
> With rng
> ....
> end wigh
> structure.
>
>
> rng.rows.count -1 just finds the number of rows in the autofilter range
> and
> subtracts 1.
>
> So if you filtered A1:C100 (100 rows), rng.rows.count -1 will give 99
> (rows).
>
> The .resize() portion means to take the size of the autofilter rng (100
> rows by
> 3 columns in my example) and change it to 99 rows by 1 column
> ".Resize(.Rows.Count - 1, 1)".
>
> But just resizing it would mean that we're looking at A1:A99. So we
> come down
> one row and over 0 columns (.offset(1,0)).
>
> So now the example will point at A2:A100.
>
> The .cells.specialcells(xlcelltypevisible) means to just use the
> visible cells
> in that column.
>
>
>
>
>
>
> jose luis wrote:
> >
> > Thank you Dave,
> >
> > I ve tried your recommendation, unfortunately I can't make run
> > smoothly. It post a message telling me "Automation error"

> "Unspecified
> > error" "Permission Denied"
> > in the line
> >
> > Code:
> > --------------------
> > "With Me.ListBox1
> > .Clear
> > --------------------
> >
> > Besides, Could you explain me what is the function of:
> >
> > Code:
> > --------------------
> > With rng
> > Set rngF = .Resize(.Rows.Count - 1, 1).Offset(1,

> 0).Cells.SpecialCells(xlCellTypeVisible)
> > End With
> > --------------------
> >
> > I'm trying to fully understand your post to implemment your
> > recomendation,
> >
> > Thanks again for your time and knowledge!
> >
> > Jose Luis
> >
> > Dave Peterson Wrote:
> > > I used the listbox from the control toolbox toolbar (ActiveX

> controls)
> > > and put
> > > it on sheet1.
> > >
> > > Then I used this code behind the worksheet.
> > >
> > > Option Explicit
> > > Private Sub Worksheet_Activate()
> > >
> > > Dim wks As Worksheet
> > > Dim rng As Range
> > > Dim rngF As Range
> > > Dim myCell As Range
> > > Dim iCtr As Long
> > >
> > > Set wks = Worksheets("sheet2")
> > > Set rng = wks.AutoFilter.Range
> > >
> > > With rng
> > > Set rngF = .Resize(.Rows.Count - 1, 1).Offset(1, 0) _
> > > .Cells.SpecialCells(xlCellTypeVisible)
> > > End With
> > >
> > > With Me.ListBox1
> > > .Clear
> > > .ColumnCount = rng.Columns.Count
> > > For Each myCell In rngF.Cells
> > > .AddItem (myCell.Value)
> > > For iCtr = 1 To rng.Columns.Count - 1
> > > .List(.ListCount - 1, iCtr) = myCell.Offset(0, iCtr).Value
> > > Next iCtr
> > > Next myCell
> > > End With
> > >
> > > End Sub
> > >
> > > If you filter the data on sheet2, then go back (and activate

> sheet1),
> > > the
> > > listbox gets updated.
> > >
> > > jose luis wrote:
> > > >
> > > > Hi,
> > > >
> > > > I have a worksheet with data (7 columns, almost 200 rows). I

> would
> > > like
> > > > to see the results of an Autofilter operation in this worksheet

> to
> > > be
> > > > "reflected" on a Listbox at another wksheet. The listbox is form
> > > Active
> > > > Control, but could be changed to a Listbox from Forms. Wich one

> is
> > > > better o easier to implemment? Could you give some direction on

> how
> > > to
> > > > procced?
> > > >
> > > > Thank you in advance,
> > > >
> > > > Regards
> > > >
> > > > Jose Luis
> > > >
> > > > --
> > > > jose luis
> > > >
> > >

> ------------------------------------------------------------------------
> > > > jose luis's Profile:
> > > http://www.excelforum.com/member.php...o&userid=13312
> > > > View this thread:
> > > http://www.excelforum.com/showthread...hreadid=381432
> > >
> > > --
> > >
> > > Dave Peterson

> >
> > --
> > jose luis
> >

> ------------------------------------------------------------------------
> > jose luis's Profile:

> http://www.excelforum.com/member.php...o&userid=13312
> > View this thread:

> http://www.excelforum.com/showthread...hreadid=381432
>
> --
>
> Dave Peterson



--
jose luis
------------------------------------------------------------------------
jose luis's Profile: http://www.excelforum.com/member.php...o&userid=13312
View this thread: http://www.excelforum.com/showthread...hreadid=381432

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      28th Jun 2005
maybe instead of checking:
if iCtr = 6 then
use:
if iCtr = rng.columns.count -1 then

(Your code worked ok for me--was it just a question about getting the format for
the last column?)

If the values in the cells are pretty, you could use .text instead of .value
(and format()).

..AddItem myCell.Text

And
..List(.ListCount - 1, iCtr) = myCell.Offset(0, iCtr).Text





jose luis wrote:
>
> Thanks Again Dave , Now the application is running smoothly. And I think
> i understood in a better way your code. Just to finish, could you guide
> me to format the last "field" in the ListBox? I wrote this but is not
> working:
>
> Code:
> --------------------
> With Sheets(1).ListBox1
> .ListFillRange = ""
> .Clear
> .ColumnCount = rng.Columns.Count
> For Each myCell In rngF.Cells
> .AddItem (myCell.Value)
> For iCtr = 1 To rng.Columns.Count - 1
> if iCtr = 6 then
> .List(.ListCount - 1, iCtr) = Format(myCell.Offset(0, iCtr).Value,"#,##0.#0")
> else
> .List(.ListCount - 1, iCtr) = myCell.Offset(0, iCtr).Value
> end if
> Next iCtr
> Next myCell
> End With
> --------------------
>
> Thank you very much for your help.
>
> Regards
>
> Jose Luis
>
> Dave Peterson Wrote:
> > My bet is you assigned the .listfillrange to a range on one of those
> > worksheets.
> >
> > You can either change the .listfillrange property to nothing manually
> > or in
> > code:
> >
> > With Me.ListBox1
> > .ListFillRange = ""
> > .Clear
> >
> > ....
> >
> > ==========
> > Set rng = wks.AutoFilter.Range
> >
> > With rng
> > Set rngF = .Resize(.Rows.Count - 1, 1).Offset(1, 0) _
> > .Cells.SpecialCells(xlCellTypeVisible)
> > End With
> >
> > Rng represents the autofilter range on your worksheet.
> >
> > the "with rng" means that everything that begins with a dot will refer
> > to rng
> > while you're in that
> >
> > With rng
> > ....
> > end wigh
> > structure.
> >
> >
> > rng.rows.count -1 just finds the number of rows in the autofilter range
> > and
> > subtracts 1.
> >
> > So if you filtered A1:C100 (100 rows), rng.rows.count -1 will give 99
> > (rows).
> >
> > The .resize() portion means to take the size of the autofilter rng (100
> > rows by
> > 3 columns in my example) and change it to 99 rows by 1 column
> > ".Resize(.Rows.Count - 1, 1)".
> >
> > But just resizing it would mean that we're looking at A1:A99. So we
> > come down
> > one row and over 0 columns (.offset(1,0)).
> >
> > So now the example will point at A2:A100.
> >
> > The .cells.specialcells(xlcelltypevisible) means to just use the
> > visible cells
> > in that column.
> >
> >
> >
> >
> >
> >
> > jose luis wrote:
> > >
> > > Thank you Dave,
> > >
> > > I ve tried your recommendation, unfortunately I can't make run
> > > smoothly. It post a message telling me "Automation error"

> > "Unspecified
> > > error" "Permission Denied"
> > > in the line
> > >
> > > Code:
> > > --------------------
> > > "With Me.ListBox1
> > > .Clear
> > > --------------------
> > >
> > > Besides, Could you explain me what is the function of:
> > >
> > > Code:
> > > --------------------
> > > With rng
> > > Set rngF = .Resize(.Rows.Count - 1, 1).Offset(1,

> > 0).Cells.SpecialCells(xlCellTypeVisible)
> > > End With
> > > --------------------
> > >
> > > I'm trying to fully understand your post to implemment your
> > > recomendation,
> > >
> > > Thanks again for your time and knowledge!
> > >
> > > Jose Luis
> > >
> > > Dave Peterson Wrote:
> > > > I used the listbox from the control toolbox toolbar (ActiveX

> > controls)
> > > > and put
> > > > it on sheet1.
> > > >
> > > > Then I used this code behind the worksheet.
> > > >
> > > > Option Explicit
> > > > Private Sub Worksheet_Activate()
> > > >
> > > > Dim wks As Worksheet
> > > > Dim rng As Range
> > > > Dim rngF As Range
> > > > Dim myCell As Range
> > > > Dim iCtr As Long
> > > >
> > > > Set wks = Worksheets("sheet2")
> > > > Set rng = wks.AutoFilter.Range
> > > >
> > > > With rng
> > > > Set rngF = .Resize(.Rows.Count - 1, 1).Offset(1, 0) _
> > > > .Cells.SpecialCells(xlCellTypeVisible)
> > > > End With
> > > >
> > > > With Me.ListBox1
> > > > .Clear
> > > > .ColumnCount = rng.Columns.Count
> > > > For Each myCell In rngF.Cells
> > > > .AddItem (myCell.Value)
> > > > For iCtr = 1 To rng.Columns.Count - 1
> > > > .List(.ListCount - 1, iCtr) = myCell.Offset(0, iCtr).Value
> > > > Next iCtr
> > > > Next myCell
> > > > End With
> > > >
> > > > End Sub
> > > >
> > > > If you filter the data on sheet2, then go back (and activate

> > sheet1),
> > > > the
> > > > listbox gets updated.
> > > >
> > > > jose luis wrote:
> > > > >
> > > > > Hi,
> > > > >
> > > > > I have a worksheet with data (7 columns, almost 200 rows). I

> > would
> > > > like
> > > > > to see the results of an Autofilter operation in this worksheet

> > to
> > > > be
> > > > > "reflected" on a Listbox at another wksheet. The listbox is form
> > > > Active
> > > > > Control, but could be changed to a Listbox from Forms. Wich one

> > is
> > > > > better o easier to implemment? Could you give some direction on

> > how
> > > > to
> > > > > procced?
> > > > >
> > > > > Thank you in advance,
> > > > >
> > > > > Regards
> > > > >
> > > > > Jose Luis
> > > > >
> > > > > --
> > > > > jose luis
> > > > >
> > > >

> > ------------------------------------------------------------------------
> > > > > jose luis's Profile:
> > > > http://www.excelforum.com/member.php...o&userid=13312
> > > > > View this thread:
> > > > http://www.excelforum.com/showthread...hreadid=381432
> > > >
> > > > --
> > > >
> > > > Dave Peterson
> > >
> > > --
> > > jose luis
> > >

> > ------------------------------------------------------------------------
> > > jose luis's Profile:

> > http://www.excelforum.com/member.php...o&userid=13312
> > > View this thread:

> > http://www.excelforum.com/showthread...hreadid=381432
> >
> > --
> >
> > Dave Peterson

>
> --
> jose luis
> ------------------------------------------------------------------------
> jose luis's Profile: http://www.excelforum.com/member.php...o&userid=13312
> View this thread: http://www.excelforum.com/showthread...hreadid=381432


--

Dave Peterson
 
Reply With Quote
 
jose luis
Guest
Posts: n/a
 
      28th Jun 2005

Thank you Dave,

Now the application is running and the numbers looking pretty .
Thanks again.

Regards

Jose Luis

Dave Peterson Wrote:
> maybe instead of checking:
> if iCtr = 6 then
> use:
> if iCtr = rng.columns.count -1 then
>
> (Your code worked ok for me--was it just a question about getting the
> format for
> the last column?)
>
> If the values in the cells are pretty, you could use .text instead of
> .value
> (and format()).
>
> ..AddItem myCell.Text
>
> And
> ..List(.ListCount - 1, iCtr) = myCell.Offset(0, iCtr).Text
>
>
>
>
>
> jose luis wrote:
> >
> > Thanks Again Dave , Now the application is running smoothly. And I

> think
> > i understood in a better way your code. Just to finish, could you

> guide
> > me to format the last "field" in the ListBox? I wrote this but is

> not
> > working:
> >
> > Code:
> > --------------------
> > With Sheets(1).ListBox1
> > .ListFillRange = ""
> > .Clear
> > .ColumnCount = rng.Columns.Count
> > For Each myCell In rngF.Cells
> > .AddItem (myCell.Value)
> > For iCtr = 1 To rng.Columns.Count - 1
> > if iCtr = 6 then
> > .List(.ListCount - 1, iCtr) = Format(myCell.Offset(0,

> iCtr).Value,"#,##0.#0")
> > else
> > .List(.ListCount - 1, iCtr) = myCell.Offset(0, iCtr).Value
> > end if
> > Next iCtr
> > Next myCell
> > End With
> > --------------------
> >
> > Thank you very much for your help.
> >
> > Regards
> >
> > Jose Luis
> >
> > Dave Peterson Wrote:
> > > My bet is you assigned the .listfillrange to a range on one of

> those
> > > worksheets.
> > >
> > > You can either change the .listfillrange property to nothing

> manually
> > > or in
> > > code:
> > >
> > > With Me.ListBox1
> > > .ListFillRange = ""
> > > .Clear
> > >
> > > ....
> > >
> > > ==========
> > > Set rng = wks.AutoFilter.Range
> > >
> > > With rng
> > > Set rngF = .Resize(.Rows.Count - 1, 1).Offset(1, 0) _
> > > .Cells.SpecialCells(xlCellTypeVisible)
> > > End With
> > >
> > > Rng represents the autofilter range on your worksheet.
> > >
> > > the "with rng" means that everything that begins with a dot will

> refer
> > > to rng
> > > while you're in that
> > >
> > > With rng
> > > ....
> > > end wigh
> > > structure.
> > >
> > >
> > > rng.rows.count -1 just finds the number of rows in the autofilter

> range
> > > and
> > > subtracts 1.
> > >
> > > So if you filtered A1:C100 (100 rows), rng.rows.count -1 will give

> 99
> > > (rows).
> > >
> > > The .resize() portion means to take the size of the autofilter rng

> (100
> > > rows by
> > > 3 columns in my example) and change it to 99 rows by 1 column
> > > ".Resize(.Rows.Count - 1, 1)".
> > >
> > > But just resizing it would mean that we're looking at A1:A99. So

> we
> > > come down
> > > one row and over 0 columns (.offset(1,0)).
> > >
> > > So now the example will point at A2:A100.
> > >
> > > The .cells.specialcells(xlcelltypevisible) means to just use the
> > > visible cells
> > > in that column.
> > >
> > >
> > >
> > >
> > >
> > >
> > > jose luis wrote:
> > > >
> > > > Thank you Dave,
> > > >
> > > > I ve tried your recommendation, unfortunately I can't make run
> > > > smoothly. It post a message telling me "Automation error"
> > > "Unspecified
> > > > error" "Permission Denied"
> > > > in the line
> > > >
> > > > Code:
> > > > --------------------
> > > > "With Me.ListBox1
> > > > .Clear
> > > > --------------------
> > > >
> > > > Besides, Could you explain me what is the function of:
> > > >
> > > > Code:
> > > > --------------------
> > > > With rng
> > > > Set rngF = .Resize(.Rows.Count - 1, 1).Offset(1,
> > > 0).Cells.SpecialCells(xlCellTypeVisible)
> > > > End With
> > > > --------------------
> > > >
> > > > I'm trying to fully understand your post to implemment your
> > > > recomendation,
> > > >
> > > > Thanks again for your time and knowledge!
> > > >
> > > > Jose Luis
> > > >
> > > > Dave Peterson Wrote:
> > > > > I used the listbox from the control toolbox toolbar (ActiveX
> > > controls)
> > > > > and put
> > > > > it on sheet1.
> > > > >
> > > > > Then I used this code behind the worksheet.
> > > > >
> > > > > Option Explicit
> > > > > Private Sub Worksheet_Activate()
> > > > >
> > > > > Dim wks As Worksheet
> > > > > Dim rng As Range
> > > > > Dim rngF As Range
> > > > > Dim myCell As Range
> > > > > Dim iCtr As Long
> > > > >
> > > > > Set wks = Worksheets("sheet2")
> > > > > Set rng = wks.AutoFilter.Range
> > > > >
> > > > > With rng
> > > > > Set rngF = .Resize(.Rows.Count - 1, 1).Offset(1, 0) _
> > > > > .Cells.SpecialCells(xlCellTypeVisible)
> > > > > End With
> > > > >
> > > > > With Me.ListBox1
> > > > > .Clear
> > > > > .ColumnCount = rng.Columns.Count
> > > > > For Each myCell In rngF.Cells
> > > > > .AddItem (myCell.Value)
> > > > > For iCtr = 1 To rng.Columns.Count - 1
> > > > > .List(.ListCount - 1, iCtr) = myCell.Offset(0, iCtr).Value
> > > > > Next iCtr
> > > > > Next myCell
> > > > > End With
> > > > >
> > > > > End Sub
> > > > >
> > > > > If you filter the data on sheet2, then go back (and activate
> > > sheet1),
> > > > > the
> > > > > listbox gets updated.
> > > > >
> > > > > jose luis wrote:
> > > > > >
> > > > > > Hi,
> > > > > >
> > > > > > I have a worksheet with data (7 columns, almost 200 rows). I
> > > would
> > > > > like
> > > > > > to see the results of an Autofilter operation in this

> worksheet
> > > to
> > > > > be
> > > > > > "reflected" on a Listbox at another wksheet. The listbox is

> form
> > > > > Active
> > > > > > Control, but could be changed to a Listbox from Forms. Wich

> one
> > > is
> > > > > > better o easier to implemment? Could you give some direction

> on
> > > how
> > > > > to
> > > > > > procced?
> > > > > >
> > > > > > Thank you in advance,
> > > > > >
> > > > > > Regards
> > > > > >
> > > > > > Jose Luis
> > > > > >
> > > > > > --
> > > > > > jose luis
> > > > > >
> > > > >
> > >

> ------------------------------------------------------------------------
> > > > > > jose luis's Profile:
> > > > >

> http://www.excelforum.com/member.php...o&userid=13312
> > > > > > View this thread:
> > > > > http://www.excelforum.com/showthread...hreadid=381432
> > > > >
> > > > > --
> > > > >
> > > > > Dave Peterson
> > > >
> > > > --
> > > > jose luis
> > > >
> > >

> ------------------------------------------------------------------------
> > > > jose luis's Profile:
> > > http://www.excelforum.com/member.php...o&userid=13312
> > > > View this thread:
> > > http://www.excelforum.com/showthread...hreadid=381432
> > >
> > > --
> > >
> > > Dave Peterson

> >
> > --
> > jose luis
> >

> ------------------------------------------------------------------------
> > jose luis's Profile:

> http://www.excelforum.com/member.php...o&userid=13312
> > View this thread:

> http://www.excelforum.com/showthread...hreadid=381432
>
> --
>
> Dave Peterson



--
jose luis
------------------------------------------------------------------------
jose luis's Profile: http://www.excelforum.com/member.php...o&userid=13312
View this thread: http://www.excelforum.com/showthread...hreadid=381432

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Pass listbox values to autofilter Ixtreme Microsoft Excel Programming 5 25th Aug 2007 01:45 PM
How to acomplish these few steps jalle Microsoft VB .NET 1 7th Dec 2006 12:46 PM
Listbox Autofilter. Doug Microsoft Access VBA Modules 0 25th May 2004 01:16 PM
AutoFilter _FilterDatabase Rowsource Listbox hgdev Microsoft Excel Programming 4 5th Mar 2004 03:39 AM
Values missing in Autofilter listbox Igors Belijs Microsoft Excel Worksheet Functions 1 30th Oct 2003 10:06 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:15 AM.