Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Macros acting on a filtered list

I have a filtered list and want to enter "SOLD" in column A for only the rows
that meet the filter criteria. I am having difficulty acting only on the
visible cells. (I am creating the macros by recording my keystrokes, not
writing VB code). Whether I enter the value in the first row and copy it
down or enter the value in each cell, and press <down arrow to move to the
next cell, the macro records specific cell addresses. If I try relative
addresses, it records that specific number of rows to move down.

Can someone provide some suggestions, or perhaps a bit of code that sets the
range to the visible cells in Col. A that I can paste over the code that
indicates specific cells?

Thanks in advance for your assistance.

Regards
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Macros acting on a filtered list

If AutoFilter hides rows then:

Sub sold()
Set r = ActiveSheet.UsedRange
nLastRow = r.Rows.Count + r.Row - 1

For i = 1 To nLastRow
If Cells(i, "A").EntireRow.Hidden Then
Else
Cells(i, "A").Value = "SOLD"
End If
Next
End Sub

--
Gary''s Student - gsnu200767


"Jay Kay" wrote:

I have a filtered list and want to enter "SOLD" in column A for only the rows
that meet the filter criteria. I am having difficulty acting only on the
visible cells. (I am creating the macros by recording my keystrokes, not
writing VB code). Whether I enter the value in the first row and copy it
down or enter the value in each cell, and press <down arrow to move to the
next cell, the macro records specific cell addresses. If I try relative
addresses, it records that specific number of rows to move down.

Can someone provide some suggestions, or perhaps a bit of code that sets the
range to the visible cells in Col. A that I can paste over the code that
indicates specific cells?

Thanks in advance for your assistance.

Regards

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Macros acting on a filtered list

Perfect. Thanks.




"Gary''s Student" wrote:

If AutoFilter hides rows then:

Sub sold()
Set r = ActiveSheet.UsedRange
nLastRow = r.Rows.Count + r.Row - 1

For i = 1 To nLastRow
If Cells(i, "A").EntireRow.Hidden Then
Else
Cells(i, "A").Value = "SOLD"
End If
Next
End Sub

--
Gary''s Student - gsnu200767


"Jay Kay" wrote:

I have a filtered list and want to enter "SOLD" in column A for only the rows
that meet the filter criteria. I am having difficulty acting only on the
visible cells. (I am creating the macros by recording my keystrokes, not
writing VB code). Whether I enter the value in the first row and copy it
down or enter the value in each cell, and press <down arrow to move to the
next cell, the macro records specific cell addresses. If I try relative
addresses, it records that specific number of rows to move down.

Can someone provide some suggestions, or perhaps a bit of code that sets the
range to the visible cells in Col. A that I can paste over the code that
indicates specific cells?

Thanks in advance for your assistance.

Regards

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Macros acting on a filtered list

Option Explicit
Sub testme()

Dim VRng As Range

With Worksheets("sheet1").AutoFilter.Range
If .Columns(1).SpecialCells(xlCellTypeVisible).Cells. Count = 1 Then
'nothing but headers are visible
MsgBox "nothing but headers"
Else
Set VRng = .Resize(.Rows.Count - 1, 1).Offset(1, 0) _
.Cells.SpecialCells(xlCellTypeVisible)
VRng.Value = "SOLD"
End If
End With

End Sub



Jay Kay wrote:

I have a filtered list and want to enter "SOLD" in column A for only the rows
that meet the filter criteria. I am having difficulty acting only on the
visible cells. (I am creating the macros by recording my keystrokes, not
writing VB code). Whether I enter the value in the first row and copy it
down or enter the value in each cell, and press <down arrow to move to the
next cell, the macro records specific cell addresses. If I try relative
addresses, it records that specific number of rows to move down.

Can someone provide some suggestions, or perhaps a bit of code that sets the
range to the visible cells in Col. A that I can paste over the code that
indicates specific cells?

Thanks in advance for your assistance.

Regards


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
A list of what is being filtered on? Mel Excel Discussion (Misc queries) 5 August 27th 08 05:08 PM
ACTING OUT DROPDOWN LIST ( OR DROPUP) FC Excel Worksheet Functions 5 March 11th 07 12:11 AM
Macros the same but not acting the same tahrah Excel Programming 0 January 9th 07 02:02 PM
Top 25 in a filtered list John Wilson Excel Programming 3 February 13th 06 12:51 AM
Macros not appearing in the Tools Macro Macros list hglamy[_2_] Excel Programming 5 October 24th 03 09:10 AM


All times are GMT +1. The time now is 06:48 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"