View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson[_5_] Dave Peterson[_5_] is offline
external usenet poster
 
Posts: 1,758
Default AutoFilter, Looping through the Rows? (Newbie)

This may get you started:

Option Explicit
Sub testme()

Dim wks As Worksheet
Dim rngF As Range
Dim myCell As Range

Set wks = ActiveSheet

If wks.AutoFilterMode = False Then
MsgBox "Please apply Data|Filter|Autofilter"
Exit Sub
End If
With wks.AutoFilter.Range
If .Columns(1).Cells.SpecialCells(xlCellTypeVisible). Count = 1 Then
'no visible cells, except for the header
Else
'get visible cells from first column of filtered range
Set rngF = .Resize(.Rows.Count - 1, 1) _
.Offset(1, 0).Cells.SpecialCells(xlCellTypeVisible)
'MsgBox rngF.Address
For Each myCell In rngF.Cells
'MsgBox myCell.Address
Next myCell
End If
End With
End Sub

It actually loops through the visible cells in the first column of the filtered
range.

Barton wrote:

Hi,

I've set an AutoFilter on Date and Company Name.
COLUMNS:
Date, Reference Number, Goods
G-VAT, Cheque Number, Services
S-VAT, New Balance, Previous Balance
Company Name

It selects 6 rows, as expected. I'm required to pre-process each row
for certain column information, i.e. ignore Cheque Number and Previous
Balance.
How can I read into an array, a line at a time, and loop round all the
selected Rows?

Thanks in advance,
Mark.


--

Dave Peterson