compare x to values in a range
X is a random integer
I want to compare X to the value in each cell in the range C965:C989 and if X matches the value in any one of those cells go back to the routine where x is generated again. |
compare x to values in a range
d.e.lindstrom wrote:
X is a random integer I want to compare X to the value in each cell in the range C965:C989 and if X matches the value in any one of those cells go back to the routine where x is generated again. Your question pretty much answers itself. This is an English-to-VBA translation: Dim cel As Range jump_target: ' X is a random integer X = Int(Rnd * 10) For Each cel In Range("C965:C989") ' I want to compare X to the value in each cell in the range ' C965:C989 and if X matches the value in any one of those cells go ' back to the routine where x is generated again. If X = cel.Value Then GoTo jump_target Next Stop Note that some people will bitch because OH NOES TEH EEEEEVIL GOTO but it's short, simple, and it works. (You can avoid GOTO via DO/LOOP or similar.) -- The good news is that events are unfolding just as foretold. The bad news is that the story ends in our utter ruin! |
compare x to values in a range
On Saturday, April 25, 2015 at 7:30:53 AM UTC+10, wrote:
X is a random integer I want to compare X to the value in each cell in the range C965:C989 and if X matches the value in any one of those cells go back to the routine where x is generated again. thx it works |
All times are GMT +1. The time now is 08:52 PM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com