LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default Trouble with looping

I am trying to write a function that loops so that I can use vlookup in
multiple ranges. The table arrays are on different sheets of the same
workbook. There are twelve of them and I have named them the month name
followed by 1(i.e. January1). The loop should go to the next range when it
does not find the value, but currently it does not. It will only calculate
for January. If someone could help that would be great.

Option Explicit
Function RRLookup(VRN As Variant) As Variant
Dim testRng As Range
Dim iCtr As Integer
Dim res As Variant


iCtr = 1
Set testRng = ThisWorkbook.Names(Format(DateSerial(2005, iCtr, 1), "mmmm")
& "1").RefersToRange
res = Application.WorksheetFunction.VLookup(VRN, testRng, 3, False)
Set testRng = Nothing
Do Until IsError(res) = False
iCtr = iCtr + 1
Set testRng = ThisWorkbook.Names(Format(DateSerial(2005, iCtr, 1),
"mmmm") & "1").RefersToRange
res = Application.WorksheetFunction.VLookup(VRN, testRng, 3, False)
Set testRng = Nothing
If iCtr = 13 Then
res = "Not Valid"
End If
Loop
RRLookup = res

End Function


 
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
Looping David T Excel Discussion (Misc queries) 2 August 30th 06 10:51 PM
looping trouble Hru48 Excel Discussion (Misc queries) 5 May 12th 06 08:35 PM
Looping Gusset Gadder Excel Programming 2 December 11th 04 09:16 PM
Looping scottwilsonx[_52_] Excel Programming 1 October 5th 04 04:13 PM
Looping trouble JC[_5_] Excel Programming 2 September 11th 03 08:22 PM


All times are GMT +1. The time now is 03:33 PM.

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

About Us

"It's about Microsoft Excel"