MrExcel Publishing
Your One Stop for Excel Tips & Solutions

include worksheet in macro

Posted by Andonny on January 29, 2001 1:19 PM

I am a little desperate. I have looked for ages in many places for an answer and I couldn't find one. Your help would be very much appreciated.

How do I incorporate mysheet (in front of the Range) into the if statement. It would save me writing macros for every worksheet in my workbook.

If Sheets("Sheet1").Cells(i, 7).Value = mysheet.Range("Q19").Value Then

Thanks a million

Posted by Andonny on January 29, 2001 1:23 PM

Re: additional information

Sorry I forgot to mention that I have set the worksheet earlier in the code with:
dim mysheet as worksheet
set mysheet=ActiveSheet

Posted by Celia on January 29, 2001 1:58 PM

Re: additional information

I'm not entirely clear what you need to do, but if you are trying to run your check on each worksheet in the workbook then try this way :-

Dim ws as Worksheet
For Each ws in Worksheets
If Sheets("Sheet1").Cells(i, 7).Value = ws.Range("Q19").Value Then
'Put your code here
End If
Next ws