Running macro over visible rows

Somewhere

New Member
Joined
Mar 1, 2013
Messages
19
Hi There

I have the following macro but needed some advise on how to update it so that it only updates visible rows?

Thanks in advance!



Sub OrderPopulate()

Dim LR As Long, i As Long

Dim order As String
Dim customer As String
Dim MinCost As String
Dim MaxCost As String
Dim Key As String

order = Range("D17").Value
customer = Range("D20").Value
MinCost = Range("D21").Value
MaxCost = Range("D22").Value
Key = Range("D23").Value


LR = Range("F" & Rows.Count).End(xlUp).Row
For i = LR To 2 Step -1

If order <> "" And customer <> "" And Right(Range("F" & i).Value, 1) = Key Then Rows(i).EntireRow.Cells(17).Value = customer
If order <> "" And MinCost <> "" And Right(Range("F" & i).Value, 1) = Key Then Rows(i).EntireRow.Cells(19).Value = MinCost
If order <> "" And MaxiCost <> "" And Right(Range("F" & i).Value, 1) = Key Then Rows(i).EntireRow.Cells(21).Value = MaxCost

Next i

End Sub
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
How about
Rich (BB code):
For i = lr To 2 Step -1
    If Rows(i).Visible Then
        If Order <> "" And customer <> "" And Right(Range("F" & i).Value, 1) = Key Then Rows(i).EntireRow.Cells(17).Value = customer
        If Order <> "" And MinCost <> "" And Right(Range("F" & i).Value, 1) = Key Then Rows(i).EntireRow.Cells(19).Value = MinCost
        If Order <> "" And MaxiCost <> "" And Right(Range("F" & i).Value, 1) = Key Then Rows(i).EntireRow.Cells(21).Value = MaxCost
    End If
Next i
 
Upvote 0
Thanks so much for your help.

I also found by using the following worked as well (y)(y)

Worksheets("Sheet1").Rows(X).RowHeight > 0 Then
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,214,832
Messages
6,121,844
Members
449,051
Latest member
excelquestion515

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top