Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 46
Default Part of VB not working

Please see code:-

Sub Sponsoracsselection()
'
' Sponsoracsselection Macro
' Macro recorded 25/09/2006 by Administrator
'

Dim res1 As Variant
Dim res2 As Variant
Dim res3 As Variant
Dim res4 As Variant

res1 = Application.VLookup(Sheets("Data").Range("SheetLoo kup"), _
Worksheets("Data").Range("DataDB"), 2, False)
res2 = Application.VLookup(Sheets("Data").Range("SheetLoo kup"), _
Worksheets("Data").Range("DataDB"), 3, False)
res3 = Application.VLookup(Sheets("Data").Range("SheetLoo kup"), _
Worksheets("Data").Range("DataDB"), 4, False)
res4 = Application.VLookup(Sheets("Data").Range("SheetLoo kup"), _
Worksheets("Data").Range("DataDB"), 5, False)

If Worksheets("Data").Range("W2") = 1 Then

If Not IsError(res1) Then
Worksheets(res1).Select
Else
MsgBox "Match not made"
End If

Else

If Worksheets("Data").Range("W2") = 2 Then

If Not IsError(res2) Then
Worksheets(res2).Select
Else
MsgBox "Match not made"
End If

Else

If Worksheets("Data").Range("W2") = 3 Then

If Not IsError(res3) Then
Worksheets(res3).Select
Else
MsgBox "Match not made"
End If

If Worksheets("Data").Range("W2") = 4 Then

If Not IsError(res4) Then
Worksheets(res4).Select
Else
MsgBox ("Match not made")
End If


End If
End If
End If
End If

End Sub

----------------

The first 3 parts work. But the fourth does not. Is there any reason why
this is happening? (res4). The first three were set up orignially than the
4th added after.

Cheers
Matt
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 46
Default Part of VB not working

Spotted what Ive missed

an else anfter the third statement.


Is there an easier way of doing this btw?

"Matthew Balch" wrote:

Please see code:-

Sub Sponsoracsselection()
'
' Sponsoracsselection Macro
' Macro recorded 25/09/2006 by Administrator
'

Dim res1 As Variant
Dim res2 As Variant
Dim res3 As Variant
Dim res4 As Variant

res1 = Application.VLookup(Sheets("Data").Range("SheetLoo kup"), _
Worksheets("Data").Range("DataDB"), 2, False)
res2 = Application.VLookup(Sheets("Data").Range("SheetLoo kup"), _
Worksheets("Data").Range("DataDB"), 3, False)
res3 = Application.VLookup(Sheets("Data").Range("SheetLoo kup"), _
Worksheets("Data").Range("DataDB"), 4, False)
res4 = Application.VLookup(Sheets("Data").Range("SheetLoo kup"), _
Worksheets("Data").Range("DataDB"), 5, False)

If Worksheets("Data").Range("W2") = 1 Then

If Not IsError(res1) Then
Worksheets(res1).Select
Else
MsgBox "Match not made"
End If

Else

If Worksheets("Data").Range("W2") = 2 Then

If Not IsError(res2) Then
Worksheets(res2).Select
Else
MsgBox "Match not made"
End If

Else

If Worksheets("Data").Range("W2") = 3 Then

If Not IsError(res3) Then
Worksheets(res3).Select
Else
MsgBox "Match not made"
End If

If Worksheets("Data").Range("W2") = 4 Then

If Not IsError(res4) Then
Worksheets(res4).Select
Else
MsgBox ("Match not made")
End If


End If
End If
End If
End If

End Sub

----------------

The first 3 parts work. But the fourth does not. Is there any reason why
this is happening? (res4). The first three were set up orignially than the
4th added after.

Cheers
Matt

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
Part of VLOOKUP not working Code Numpty Excel Worksheet Functions 4 December 10th 08 02:05 PM
i am working with excel sheet. in the calculation part i want if srinivas Excel Programming 1 April 27th 06 08:14 PM
2nd part of formula not working dbl Excel Worksheet Functions 3 October 17th 05 08:01 PM
Array not working correctly Returns FALSE on second part aaronm49 Excel Discussion (Misc queries) 1 February 11th 05 01:07 AM
Shell command stopped working: is it part of Excel 95 , or Windows? Charles Jordan Excel Programming 9 May 4th 04 06:39 AM


All times are GMT +1. The time now is 01:25 AM.

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"