Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
 
Posts: n/a
Default VLOOKUP from another sheet, VBA

hi,

I have 2 sheets in my workbook,

sheet 1 contains the main analysis of my data

sheet 2 contains a table which I will reference with VLOOKUP from sheet 1


I have written the following VBA code for my purpose:
Worksheets(1).Activate //activate sheet 1
Range("M2").FormulaR1C1 = "=VLOOKUP(RC[-5], lookuptable'!$A2:$B38, 2,
false)" //input into cell M2 of sheet 1 this formula.

when I run my code,
cell M2 in sheet 1 will give a #NAME? error and when I look at the formula
in the cell:
=VLOOKUP(H2,personal.xls!'A2':'B38',2,FALSE)

notice the extra single quotes around A2 and B38.

ps: i defined my module in personal.xls to be able to access it from any
workbook.

thnks.
Michael.

  #2   Report Post  
Gordon
 
Posts: n/a
Default

<a wrote in message ...
hi,

I have 2 sheets in my workbook,

sheet 1 contains the main analysis of my data

sheet 2 contains a table which I will reference with VLOOKUP from sheet 1


I have written the following VBA code


I might be missing something here, but why VBA code? Won't just an ordinary
VLOOKUP do what you want, especially as it's looking up a sheet in the same
workbook?


  #3   Report Post  
 
Posts: n/a
Default

I am trying to automate the whole process so that
at the press of a button, the data processing and analysis can be done .

yes, it works if it is just a normal formula in a cell.
but in VBA, i have problems referencing it .


"Gordon" wrote in message
...
<a wrote in message ...
hi,

I have 2 sheets in my workbook,

sheet 1 contains the main analysis of my data

sheet 2 contains a table which I will reference with VLOOKUP from sheet 1


I have written the following VBA code


I might be missing something here, but why VBA code? Won't just an
ordinary VLOOKUP do what you want, especially as it's looking up a sheet
in the same workbook?


  #4   Report Post  
KL
 
Posts: n/a
Default

Hi,

I guess it is clearly beacuse you are mixing the R1C1 notation (RC[-5]) with A1 notation ($A2:$B38) in one formula. Also you use only one '-sign whereas it should be on both sides of the sheet name (actually with this name they aren't necessary at all as there are no spaces in it). Besides you are explicitly saying it is a R1C1 formula by "Range("M2").FormulaR1C1=". Try this:

Range("M2").FormulaR1C1="=VLOOKUP(RC[-5], lookuptable!R[-3]C1:R[33]C2, 2,0)"

Regards,
KL



<a wrote in message ...
hi,

I have 2 sheets in my workbook,

sheet 1 contains the main analysis of my data

sheet 2 contains a table which I will reference with VLOOKUP from sheet 1


I have written the following VBA code for my purpose:
Worksheets(1).Activate //activate sheet 1
Range("M2").FormulaR1C1 = "=VLOOKUP(RC[-5], lookuptable'!$A2:$B38, 2,
false)" //input into cell M2 of sheet 1 this formula.

when I run my code,
cell M2 in sheet 1 will give a #NAME? error and when I look at the formula
in the cell:
=VLOOKUP(H2,personal.xls!'A2':'B38',2,FALSE)

notice the extra single quotes around A2 and B38.

ps: i defined my module in personal.xls to be able to access it from any
workbook.

thnks.
Michael.

  #5   Report Post  
Gordon
 
Posts: n/a
Default

<a wrote in message ...
I am trying to automate the whole process so that
at the press of a button, the data processing and analysis can be done .


But you are referencing a sheet in the same workbook, so when you open the
workbook, the VLOOKUP will automatically update! So I ask again, am I
missing something? Why the VBA?




  #6   Report Post  
KL
 
Posts: n/a
Default

....actually, I would do this:

Range("M2").FormulaR1C1 = "=VLOOKUP(RC[-5], lookuptable!R2C1:R38C2, 2,0)"

Regards,
KL


"KL" wrote in message ...
Hi,

I guess it is clearly beacuse you are mixing the R1C1 notation (RC[-5]) with A1 notation ($A2:$B38) in one formula. Also you use only one '-sign whereas it should be on both sides of the sheet name (actually with this name they aren't necessary at all as there are no spaces in it). Besides you are explicitly saying it is a R1C1 formula by "Range("M2").FormulaR1C1=". Try this:

Range("M2").FormulaR1C1="=VLOOKUP(RC[-5], lookuptable!R[-3]C1:R[33]C2, 2,0)"

Regards,
KL



<a wrote in message ...
hi,

I have 2 sheets in my workbook,

sheet 1 contains the main analysis of my data

sheet 2 contains a table which I will reference with VLOOKUP from sheet 1


I have written the following VBA code for my purpose:
Worksheets(1).Activate //activate sheet 1
Range("M2").FormulaR1C1 = "=VLOOKUP(RC[-5], lookuptable'!$A2:$B38, 2,
false)" //input into cell M2 of sheet 1 this formula.

when I run my code,
cell M2 in sheet 1 will give a #NAME? error and when I look at the formula
in the cell:
=VLOOKUP(H2,personal.xls!'A2':'B38',2,FALSE)

notice the extra single quotes around A2 and B38.

ps: i defined my module in personal.xls to be able to access it from any
workbook.

thnks.
Michael.

  #7   Report Post  
 
Posts: n/a
Default

thanks alot.

since i am at cell M2 on sheet 1,
the code : lookuptable!R[-3]C1:R[33]C2 is taking pivot from which cell?
should i take reference from A1 since this is on sheet 2.

also, i am going to copy this whole formula down the column, will R1C1
formula automatically shift the referencing for me?
i.e. if M2 calculates from cell H2, M3 will calculate from cell H3.

thanks again.

"KL" wrote in message
...
Hi,

I guess it is clearly beacuse you are mixing the R1C1 notation (RC[-5])
with A1 notation ($A2:$B38) in one formula. Also you use only one '-sign
whereas it should be on both sides of the sheet name (actually with this
name they aren't necessary at all as there are no spaces in it). Besides you
are explicitly saying it is a R1C1 formula by "Range("M2").FormulaR1C1=".
Try this:

Range("M2").FormulaR1C1="=VLOOKUP(RC[-5], lookuptable!R[-3]C1:R[33]C2,
2,0)"

Regards,
KL



<a wrote in message ...
hi,

I have 2 sheets in my workbook,

sheet 1 contains the main analysis of my data

sheet 2 contains a table which I will reference with VLOOKUP from sheet

1


I have written the following VBA code for my purpose:
Worksheets(1).Activate //activate sheet 1
Range("M2").FormulaR1C1 = "=VLOOKUP(RC[-5], lookuptable'!$A2:$B38, 2,
false)" //input into cell M2 of sheet 1 this formula.

when I run my code,
cell M2 in sheet 1 will give a #NAME? error and when I look at the

formula
in the cell:
=VLOOKUP(H2,personal.xls!'A2':'B38',2,FALSE)

notice the extra single quotes around A2 and B38.

ps: i defined my module in personal.xls to be able to access it from any
workbook.

thnks.
Michael.


  #8   Report Post  
KL
 
Posts: n/a
Default

Hi,

since i am at cell M2 on sheet 1,
the code : lookuptable!R[-3]C1:R[33]C2 is taking pivot from which cell? should i take reference from A1 since this is on sheet 2.


I am not sure what you mean by this :-(
The reference to table should be lookuptable!R2C1:R38C2 if you want $A$1:$B$38

also, i am going to copy this whole formula down the column, will R1C1 formula automatically shift the referencing for me?
i.e. if M2 calculates from cell H2, M3 will calculate from cell H3.


Yes, it will.

Regards,
KL
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
vlookup and filename returning same result on each sheet. RogueSwan Excel Discussion (Misc queries) 3 March 22nd 05 10:08 PM
Copying multiple sheets from one book 2 another and undertake spec Pank Mehta Excel Discussion (Misc queries) 14 March 16th 05 04:41 PM
vlookup...transferring info from 1 sheet to another.... trey braid Excel Worksheet Functions 3 February 3rd 05 05:33 AM
vlookup with data on more than one sheet Greegan Excel Worksheet Functions 1 December 21st 04 03:34 AM
Naming & renaming a sheet tab Cgbilliar Excel Worksheet Functions 1 November 7th 04 05:57 PM


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