Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Vlookup in vba - how to use absolute rows not relative

Hi

I have the following snippet of code:

Sheets("mdata").Select
Range("E1").Select
ActiveCell.FormulaR1C1 = "RVU"
Range("E2").Select
ActiveCell.FormulaR1C1 =
"=IF(ISNA(VLOOKUP(RC[-1],rvu!R[-1]C[-4]:R[7238]C[-3],2)),0,VLOOKUP(RC[-1],rvu!R[-1]C[-4]:R[7238]C[-3],2))"
Range("E2").Select
Selection.AutoFill Destination:=Range("E2:E" & LastRow),
Type:=xlFillDefault

This fills about 5,000 rows with look up data from the rvu ws, and puts in 0
if #N/A is obtained. HOWEVER, if I was just using VLookup as a formula, I
would use =VLOOKUP(E2,'cases-dump'!A$2:B$7238,2) so that as I fill the
formula down the column, I keep the same constant reference from the rvu look
up sheet. As is, the vba formula keeps incrementing the rows and I get all
0's at the end.
How do I correct this?

Thanks in advance!

clsnyder
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Vlookup in vba - how to use absolute rows not relative

Try the below

Sub Macro()

Dim lngLastRow As Long, ws As Worksheet

Set ws = Sheets("mdata")

lngLastRow = ws.Cells(Rows.Count, "A").End(xlUp).Row
ws.Range("E1").Value = "RVU"
ws.Range("E2:E" & lngLastRow).Formula = _
"=VLOOKUP(E2,'Cases-dump'!$A$2:$B$7238,2,0)"

End Sub


--
Jacob (MVP - Excel)


"clsnyder" wrote:

Hi

I have the following snippet of code:

Sheets("mdata").Select
Range("E1").Select
ActiveCell.FormulaR1C1 = "RVU"
Range("E2").Select
ActiveCell.FormulaR1C1 =
"=IF(ISNA(VLOOKUP(RC[-1],rvu!R[-1]C[-4]:R[7238]C[-3],2)),0,VLOOKUP(RC[-1],rvu!R[-1]C[-4]:R[7238]C[-3],2))"
Range("E2").Select
Selection.AutoFill Destination:=Range("E2:E" & LastRow),
Type:=xlFillDefault

This fills about 5,000 rows with look up data from the rvu ws, and puts in 0
if #N/A is obtained. HOWEVER, if I was just using VLookup as a formula, I
would use =VLOOKUP(E2,'cases-dump'!A$2:B$7238,2) so that as I fill the
formula down the column, I keep the same constant reference from the rvu look
up sheet. As is, the vba formula keeps incrementing the rows and I get all
0's at the end.
How do I correct this?

Thanks in advance!

clsnyder

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
Absolute to Relative Referencing sgltaylor Excel Programming 3 November 30th 09 06:41 AM
Relative and absolute hyperlinks Musette New Users to Excel 2 October 4th 07 06:47 AM
Absolute to Relative hawki Excel Programming 3 May 14th 07 08:11 PM
Mix of relative and absolute? M John Excel Programming 4 April 27th 06 04:24 PM
Chg Absolute to Relative Adresmith[_8_] Excel Programming 1 October 29th 04 07:23 PM


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