Apply VBA code only to filtered rows

Nicoko

New Member
Joined
Nov 3, 2023
Messages
4
Office Version
  1. 2007
Platform
  1. Windows
Hello
i have a VBA code that perform some tasks on the complete excel table, till he doesn t find anymore rows.
the row selection is for now like that:
For i = 4 To Range("c65536").End(xlUp).Row

I would need to apply some filter on the table to have the VBA code to apply only to the filtered rows.
How could i modify/add code so that VBA is only executed to filtered rows?

Thx in advance!

BR
Nicolas
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
You test if each row is unhidden or visible but with out seeing the actual code that you are using there is not anything I can advise.
Please paste your full code in the thread in code tags (select the pasted code and click the
1699031043766.png
icon as the top of the reply window) and click reply
 
Upvote 0
VBA Code:

Sub fct()
Dim i As Long
Dim strto As String
For i = 4 To Range("c65536").End(xlUp).Row ' table start at line 4
strto = Cells(i, x) & Cells(i, y) 'some cell info from line i, column x and column y
' then for each i code do something with strto
End Sub
 
Upvote 0
VBA Code:
strto = Cells(i, x) & Cells(i, y)
That line is not a working code line with what is before it in the code. We need to see the actual working code, that means copy and paste the actual working code.
 
Upvote 0
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim i As Long
For i = 4 To Range("C65536").End(xlUp).Row
If Range("G" & i) = "" And Range("C" & i) = "Yes" Then Range("G" & i) = Date
Next i
End Sub
 
Upvote 0
Not sure about the code running at every cell change but try...

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim i As Long
    For i = 4 To Range("C" & Rows.Count).End(xlUp).Row
        If Rows(i).Rows.Height > 0 Then
            If Range("G" & i) = "" And Range("C" & i) = "Yes" Then Range("G" & i) = Date
        End If
    Next i
End Sub
 
Upvote 0
amazing - Thx ! you re fast and correct . Many thx!
 
Upvote 0

Forum statistics

Threads
1,215,093
Messages
6,123,067
Members
449,090
Latest member
fragment

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