Excel97+referring to another worksheet in VBA

  csqwared 16:08 23 Jan 2008
Locked

Hi

I'm working on a workbook trying to utilise my limited knowledge of Excel VBA and so far it's gone quite well. However, I'm now stuck. What I am trying to do is look at a cell in worksheet1 and compare it with a lot of cells in worksheet2 and if they are the same set certain parameters in worksheet1. My idea was to use a nested loop but for the life of me can't hit on the right syntax. I have a couple of reference books but just can't crack it. My code (in worksheet1) is:-

for g = 1 to 20
for a = 1 to 20
if cells(a,"a") = (this is the bit I can't get right) 'worksheet2'!.cells(g,"a") then...........

I've tried all sorts of variations for the last part, even recorded a macro to see how that did it with no success. Any help would be much appreciated.

Thanks

cc

  VoG II 18:48 23 Jan 2008

If Sheets("Sheet1").Cells(a, "A").Value = Sheets("Sheet2").Cells(g, "A").Value Then

  csqwared 14:26 24 Jan 2008

That works perfectly - thanks very much.

cc

This thread is now locked and can not be replied to.

Elsewhere on IDG sites

Intel Coffee Lake release date and specifications

12 Amazing British Craft Beer Label Designs

watchOS 4 review

Les meilleurs navigateurs internet 2017