Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default EXCEL FORMULA TO VB

Hi
i have a formula which works fine in excel but i cannot get written in VB.
Presume in my limited knowledge of VB that it should be if / else if etc. The
excel formula is:-


=IF(B1995=1,VLOOKUP(A1995,'Pay
Rates'!$A$2:$H$5000,8,FALSE),IF(B1995=2,VLOOKUP(A1 995,'Pay
Rates'!$A$2:$H$5000,7,FALSE),IF(B1995=3,VLOOKUP(A1 995,'Pay
Rates'!$A$2:$H$5000,6,FALSE),IF(B1995=4,VLOOKUP(A1 995,'Pay
Rates'!$A$2:$H$5000,5,FALSE)))))

any help would be much appreciated.

Thanks
Sarah
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default EXCEL FORMULA TO VB

Not sure why you'd want to do this in VB - easier, and FAR more
efficient to use:

=VLOOKUP(A1995,'Pay Rates'!$A$2:$H$5000,9-B1995,FALSE)

or, if error checking for B1995 is required:

=IF(AND(B1995=1,B1995<=4),VLOOKUP(A1995,'Pay
Rates'!$A$2:$H$5000,9-B1995,FALSE))


However, "written in VB" is pretty ambiguous. One way:

Dim vResult As Variant
Dim vTarget As Variant
Dim vCol As Variant
Dim rLookup As Range

vTarget = ActiveSheet.Range("A1995").Value
vCol = ActiveSheet.Range("B1995").Value
Set rLookup = Worksheets("Pay Rates").Range("A2:H5000")
Select Case vCol
Case 1 To 4
vResult = Application.VLookup(vTarget, rLookup, _
9 - vCol, False)
Case Else
vResult = "Error"
End Select
MsgBox vResult



In article ,
soz1967 wrote:

Hi
i have a formula which works fine in excel but i cannot get written in VB.
Presume in my limited knowledge of VB that it should be if / else if etc. The
excel formula is:-


=IF(B1995=1,VLOOKUP(A1995,'Pay
Rates'!$A$2:$H$5000,8,FALSE),IF(B1995=2,VLOOKUP(A1 995,'Pay
Rates'!$A$2:$H$5000,7,FALSE),IF(B1995=3,VLOOKUP(A1 995,'Pay
Rates'!$A$2:$H$5000,6,FALSE),IF(B1995=4,VLOOKUP(A1 995,'Pay
Rates'!$A$2:$H$5000,5,FALSE)))))

any help would be much appreciated.

Thanks
Sarah

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
Excel 2002 Formula: Urgent Conditional Formula Required Right Away - if possible blue[_2_] Excel Discussion (Misc queries) 2 July 11th 07 06:08 PM
Build excel formula using field values as text in the formula val kilbane Excel Worksheet Functions 2 April 18th 07 01:52 PM
match formula - 2 excel files:#1 hasthis formula, 2nd has the Raw DS Excel Worksheet Functions 4 October 7th 06 12:25 AM
Excel 2002 formula displayed not value formula option not checked Dean Excel Worksheet Functions 1 February 28th 06 02:31 PM
i edit a formula (excel) then it displays formula not answer caiman Excel Discussion (Misc queries) 2 September 9th 05 02:09 AM


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