Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default 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.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 538
Default 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!
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default 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
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Compare values of cells in a range Dale Fye Excel Programming 5 December 15th 07 08:20 AM
Find duplicate values in column K then compare cells range of dups jonnybrovo815 Excel Programming 0 July 25th 07 07:52 PM
How do I compare a result to a range of values? UnisourceforNPH Excel Worksheet Functions 6 June 12th 07 08:09 PM
Compare alpha and numeric values within a range Greg Excel Worksheet Functions 9 May 5th 06 05:17 AM


All times are GMT +1. The time now is 06:27 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"