LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 46
Default Vary Vlookup column ref in vba

Hi everyone. I'm automating a report, and am writing a vlookup formula.
But based on the month on the report, I need the column ref # in the lookup
formula to vary. The report is setup in a trend fashion, with Dec 04 in
column E going all the way out to Dec 06 in column AC. So, vba looks in
cell C2 to determine how many columns to the right to begin the formula,
then it resizes 13 columns for 13 months to be formulated. In row 3 of each
month, I have the column ref # that I want in the vlookup. How can I vary
the formula code in such a way that vba knows what cell ref to put in the
column ref # field? in other words, in the formula below, if I the report
is for October 06, I need O$4. But if I choose Nov 06, then my offset in
cell C2 is 1 larger, which begins the formula in column P. Its like I need
an "activecell.column, row 3" syntax, except I'm not actually selecting the
cells. Thanks for any help!


os = Worksheets("Book I").Range("C2").Value 'the offset value to begin
the formula
For Each cl In Range("D1:D19") 'flag to tell vba whether or not to
formulate that row
If Not IsEmpty(cl) Then
cl.Offset(0, os).Resize(1, 13).Formula = _
"=VLOOKUP($A" & cl.Row & ",Data!$A$7:$P$750,O$4,0)" 'O needs to vary
based on offset
End If
Next cl


 
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
How can I vary the row number or column alphabet depending on my n Tigerxxx Excel Discussion (Misc queries) 7 December 26th 07 06:46 PM
vary the vlookup array depending on the value in a cell Greg Bergin Excel Worksheet Functions 1 June 14th 06 08:58 AM
Vary column to sum in SumIf Steph Excel Worksheet Functions 2 April 3rd 06 07:23 PM
Vary column width and row height in the same worksheet Tess Excel Discussion (Misc queries) 1 August 4th 05 03:39 PM
Vary the column widths for different rows Marty Excel Discussion (Misc queries) 2 January 4th 05 11:08 PM


All times are GMT +1. The time now is 06:59 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"