Excel97+referring to another worksheet in VBA

  csqwared 16:08 23 Jan 08


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.



  VoG II 18:48 23 Jan 08

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

  csqwared 14:26 24 Jan 08

That works perfectly - thanks very much.


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

What is ransomware and how do I protect my PC from WannaCry?

What I learned from my mentor, Oscar-winning VFX supervisor Phil Tippett

Siri vs Google Assistant