Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 45
Default lookup horizontal...

Have this range D2:CE2 filled with a many value and a My_var filled
with a value
I want to find in this range if value of My_var existis in range
D2:CE2... if existis goto other code1 else goto other code2 how to in
VBA?
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 11,501
Default lookup horizontal...

Hi,

Right click your sheet, view code and paste this in

Sub nn()
my_var = 99
Set myrange = Range("D2:CE2")
On Error Resume Next
For Each c In myrange
If c.Value = my_var Then
'run code1
Else
'run code2
End If
Next
End Sub

You must consider what you do after you have run code1 or code2 because
execution will return back into this routine. You could do this

If c.Value = my_var Then
'run code1
exit sub
Else
'run code2
exit sub
End If



Mike


"sal21" wrote:

Have this range D2:CE2 filled with a many value and a My_var filled
with a value
I want to find in this range if value of My_var existis in range
D2:CE2... if existis goto other code1 else goto other code2 how to in
VBA?

  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 11,501
Default lookup horizontal...

Ignore my last post I had an elderly moment, try this instead

Sub nn()
my_var = 999
Set myrange = Range("D2:CE2")
On Error Resume Next
For Each c In myrange
If c.Value = my_var Then
code1
Exit Sub
End If
Next
code2
End Sub

Sub code1()
MsgBox 1
End Sub


Sub code2()
MsgBox 2
End Sub

"Mike H" wrote:

Hi,

Right click your sheet, view code and paste this in

Sub nn()
my_var = 99
Set myrange = Range("D2:CE2")
On Error Resume Next
For Each c In myrange
If c.Value = my_var Then
'run code1
Else
'run code2
End If
Next
End Sub

You must consider what you do after you have run code1 or code2 because
execution will return back into this routine. You could do this

If c.Value = my_var Then
'run code1
exit sub
Else
'run code2
exit sub
End If



Mike


"sal21" wrote:

Have this range D2:CE2 filled with a many value and a My_var filled
with a value
I want to find in this range if value of My_var existis in range
D2:CE2... if existis goto other code1 else goto other code2 how to in
VBA?

  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 45
Default lookup horizontal...

On 14 Apr, 14:46, Mike H wrote:
Ignore my last post I had an elderly moment, try this instead

Sub nn()
my_var = 999
Set myrange = Range("D2:CE2")
On Error Resume Next
For Each c In myrange
* * If c.Value = my_var Then
* * * * code1
* * * * Exit Sub
* * End If
Next
code2
End Sub

Sub code1()
* * * * *MsgBox 1
End Sub

Sub code2()
* * * MsgBox 2
End Sub



"Mike H" wrote:
Hi,


Right click your sheet, view code and paste this in


Sub nn()
my_var = 99
Set myrange = Range("D2:CE2")
On Error Resume Next
For Each c In myrange
If c.Value = my_var Then
* * * * 'run code1
* * Else
* * * * * *'run code2
* * End If
Next
End Sub


You must consider what you do after you have run code1 or code2 because
execution will return back into this routine. You could do this


If c.Value = my_var Then
* * * * 'run code1
* * * * *exit sub
* * Else
* * * * * *'run code2
* * * * * *exit sub
* * End If


Mike


"sal21" wrote:


Have this range D2:CE2 filled with a many value and a My_var filled
with a value
I want to find in this range if value of My_var existis in range
D2:CE2... if existis goto other code1 else goto other code2 how to in
VBA?- Nascondi testo tra virgolette -


- Mostra testo tra virgolette -


Excellent code!
Tks.

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
Need lookup of data both vertical and horizontal rmargh Excel Discussion (Misc queries) 2 November 21st 07 05:10 PM
how do i set up a horizontal spreadsheet? April Excel Worksheet Functions 2 August 8th 07 03:59 PM
Horizontal Filtering Ed Excel Discussion (Misc queries) 5 August 23rd 06 12:29 AM
Sumproduct and horizontal lookup Gingit Excel Discussion (Misc queries) 3 June 13th 06 12:59 AM
Horizontal split D'oug New Users to Excel 4 April 10th 05 04:36 AM


All times are GMT +1. The time now is 02:28 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"