Hi,
I built the code below which calls my vlookup function and places the values automatically based on specified wks. It works like a charm!
*My problem: I have another wks "Sheet2" which I would like to *DIVIDE* by 100 the values from my Vlookup. So I have attached the workbook with my formula in excel and I have also inserted where I am having trouble in the macro!
I built the code below which calls my vlookup function and places the values automatically based on specified wks. It works like a charm!
*My problem: I have another wks "Sheet2" which I would like to *DIVIDE* by 100 the values from my Vlookup. So I have attached the workbook with my formula in excel and I have also inserted where I am having trouble in the macro!
Code:
Sub Test1()
Dim ws As Worksheet
Dim lastCol As Long
Dim lastRow As Long
On Error Resume Next 'trap for data in "iv"
For Each ws In ActiveWorkbook.Worksheets
With ws
.Activate
lastCol = Range("IV2").End(xlToLeft).Column
lastRow = Range("A65536").End(xlUp).Row
'Determine Select Case
Select Case .Name
Case "Sheet1":
FullPath = ThisWorkbook.Path
WbName = "Book1.xls"
ShName = "Table1"
SourceRng = "C1:C6"
ReturnColNum = 3
'************************
'Case "Sheet2":
'Divide values by 100 found from Vlookup Function
'ie: ="(100/VLOOKUP(SrcValue;Table1,C1:C6,3,False))"
'How can I add this??
'*************************
End Select
' Call Vlookup with Variables
For rw = 2 To lastRow
SrcValue = .Cells(rw, 1).Value
.Cells(rw, lastCol + 1).Value = RemoteVlookUp(SrcValue, FullPath, WbName, ShName, SourceRng, ReturnColNum)
Next rw
End With
Next ws
End Sub
Private Function RemoteVlookUp(SrcValue, FullPath, WbName, ShName, SourceRng, ReturnColNum) As String
Dim ReturnedValue As String
' NOTE: error will occur even if value cannot be found and everything else is OK
On Error GoTo ErrHandler
If Not Right(FullPath, 1) = "\" Then FullPath = FullPath & "\"
ReturnedValue = ExecuteExcel4Macro("VLOOKUP(""" & SrcValue & _
""",'" & FullPath & _
"[" & WbName & "]" & _
ShName & "'!" _
& SourceRng & "," _
& ReturnColNum & ",FALSE)")
RemoteVlookUp = ReturnedValue
Exit Function
ErrHandler:
RemoteVlookUp = VlookupNA
End Function