Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 542
Default Vlookup in VBA - Driving me crazy


Hi Experts

I would highly appreciate if you could help me solve this mystery.

I have created the following function which let me perform Vlookups on any
workbook.sheet.
Its part of a bigger project & I have put it on server for everyone on
access it.
It works fine when I run it on my machine which has XL 2003 sp1 & so dose it
works fine on may other machines, however some of the users (with same EXCEL
version) get the following error

"Subscript out of range" on line with staement <Set wks =
Workbooks(WB).Sheets(Sheet) on debusing Sheet = "subscript out of range"

The crazy thing is it works without hitch on mine & as well as few other
machines, just few of them it does not, what could it be, the progam
code/files calls all remain same???

Please advise as I am pulling my hair out as this where my VBA knowledge ends.


Function SearchSku(Pno As String, WB As String, Sheet As String, SCol As
Long, GetCol As Long)
Res = ""
'Set r = Workbooks(ThisWorkbook.Name).Sheets(Sheet).Range(S Col &
":IV60000")
Dim wks As Worksheet

Set wks = Workbooks(WB).Sheets(Sheet)
Set r = wks.Range(wks.Cells(1, SCol), wks.Range("IV60000"))

Res = Application.VLookup(Pno, r, GetCol, False)
If IsError(Res) Then
SearchSku = "n/a"
Else
SearchSku = Res
End If

End Function



Thanks a lot
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Vlookup in VBA - Driving me crazy

Not much to tell except that the error indicates that there's no sheet
Sheet in Workbook WB.

Have you checked for extraneous characters in the sheet name (or in the
input)?

Are you sure you're calling the right WB? Is it open on others' machines?

In article ,
"James" wrote:

Hi Experts

I would highly appreciate if you could help me solve this mystery.

I have created the following function which let me perform Vlookups on any
workbook.sheet.
Its part of a bigger project & I have put it on server for everyone on
access it.
It works fine when I run it on my machine which has XL 2003 sp1 & so dose it
works fine on may other machines, however some of the users (with same EXCEL
version) get the following error

"Subscript out of range" on line with staement <Set wks =
Workbooks(WB).Sheets(Sheet) on debusing Sheet = "subscript out of range"

The crazy thing is it works without hitch on mine & as well as few other
machines, just few of them it does not, what could it be, the progam
code/files calls all remain same???

Please advise as I am pulling my hair out as this where my VBA knowledge ends.


Function SearchSku(Pno As String, WB As String, Sheet As String, SCol As
Long, GetCol As Long)
Res = ""
'Set r = Workbooks(ThisWorkbook.Name).Sheets(Sheet).Range(S Col &
":IV60000")
Dim wks As Worksheet

Set wks = Workbooks(WB).Sheets(Sheet)
Set r = wks.Range(wks.Cells(1, SCol), wks.Range("IV60000"))

Res = Application.VLookup(Pno, r, GetCol, False)
If IsError(Res) Then
SearchSku = "n/a"
Else
SearchSku = Res
End If

End Function



Thanks a lot

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 HELP!! IF OR formula driving me crazy!!!! caz - can't use excel!! Excel Discussion (Misc queries) 8 August 13th 09 09:07 PM
Driving me CRAZY~ please help Tara New Users to Excel 0 July 7th 08 07:29 PM
VLOOKUP driving me crazy LB79 Excel Discussion (Misc queries) 5 December 13th 05 04:14 PM
It doesn't add up - It's driving me crazy Francis Hayes (The Excel Addict) Excel Programming 10 February 28th 05 10:40 PM
Driving me crazy! Dick Kusleika[_3_] Excel Programming 0 October 21st 03 10:18 PM


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