Add sheet2 name in For..Each loop code..

VBABEGINER

Well-known Member
Joined
Jun 15, 2011
Messages
1,232
I have new question here..
Please see my below code..

In red line code, I want to use Sheet2 now..How do i edit this..can any help..

Code:
Dim FndTxt As Range, zVal As Range, Fnd As Long
Set FndTxt = Range("AA3")
[COLOR=#ff0000]For Each zVal In Range("Z501", Range("Z" & Rows.Count).End(xlUp))[/COLOR]
    **** = WorksheetFunction.CountIf(Range("AA3", Cells(LastRow, LastCol)), zVal.Value)
    If **** > 0 Then
        For Fnd = 1 To ****
            Set FndTxt = Range("AA3", Cells(LastRow, LastCol)).Find(What:=zVal.Value, After:=FndTxt, _
            LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
            Range("A" & FndTxt.Row).Interior.Color = vbGreen
        Next Fnd
    End If
Next zVal
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Do you mean
a) Sheet index 2 (ie the 2nd sheet in the workbook)?
b) A sheet called "Sheet2"?
c) The sheet CodeName "Sheet2"?
 
Upvote 0
This does not answer my question.
 
Upvote 0
OK,Try this
Code:
For Each zVal In Sheets("Sheet2").Range("Z501", Sheets("Sheet2").Range("Z" & Rows.Count).End(xlUp))
 
Upvote 0
Glad to help & thanks for the feedback.

Please do not post continuations of one thread to other threads
Thanks
 
Upvote 0

Forum statistics

Threads
1,215,377
Messages
6,124,598
Members
449,174
Latest member
chandan4057

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