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

VBABEGINER

Well-known Member
Joined
Jun 15, 2011
Messages
1,284
Office Version
  1. 365
Platform
  1. Windows
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

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
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
Ohh, pretty easy..Thanks fro this.



OK,Try this
Code:
For Each zVal In Sheets("Sheet2").Range("Z501", Sheets("Sheet2").Range("Z" & Rows.Count).End(xlUp))
 
Last edited by a moderator:
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,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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