Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Vlookup - column index number - create as variable

I'm writing the following code to fill spreadsheets with
vlookup formulas. I can get the formula to be put in the
rows down & across that I need to fill, but what I want
to be able to do is create a variable so that the
col_index_num in the vlookup changes as the formula is
placed into that colum.

variable = 1 to 10
eg - =vlookup(a1,a5:f10,PUT VARIABLE HERE,0)
next variable

is this possible ????



Sub Macro20()
'
' Macro20 Macro
' Macro recorded 5/08/2004 by John Young
Dim rowcount As Integer
Dim columncount As Integer
Dim cellcountdown As Integer
Dim cellcountacross As Integer

Sheets("g419015_2_lf6_intersect_summari").Activate

Range("a2", Range("a2").End(xlDown)).Select
rowcount = Selection.Rows.Count

Range("g1", Range("g1").End(xlToRight)).Select
columncount = Selection.Columns.Count


For cellcountdown = 2 To (rowcount + 1)

For cellcountacross = 1 To columncount

'Cells(cellcountdown, (cellcountacross +
6)).VALUE = "=VLOOKUP(RC[-
1],'[BHSTStateRegister_TESTJY.xls]Broad Hydrological Soil
Types'!R2C1:R201C63,2,FALSE)"
'Cells(cellcountdown, (cellcountacross +
6)).VALUE = "=VLOOKUP(RC[-
1],'[BHSTStateRegister_TESTJY.xls]Broad Hydrological Soil
Types'!R2C1:R201C63,2,FALSE)"
Cells(cellcountdown, (cellcountacross + 6)).VALUE
= "=VLOOKUP(RC[-1],'[BHSTStateRegister_TESTJY.xls]Broad
Hydrological Soil Types'!R2C1:R201C63,RC[1],FALSE)"

Next cellcountacross

Next cellcountdown



Range("A2").Select
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Vlookup - column index number - create as variable

=vlookup(a1,a5:f10,column(A1),0)

--
Regards,
Tom Ogilvy

"john young" wrote in message
...
I'm writing the following code to fill spreadsheets with
vlookup formulas. I can get the formula to be put in the
rows down & across that I need to fill, but what I want
to be able to do is create a variable so that the
col_index_num in the vlookup changes as the formula is
placed into that colum.

variable = 1 to 10
eg - =vlookup(a1,a5:f10,PUT VARIABLE HERE,0)
next variable

is this possible ????



Sub Macro20()
'
' Macro20 Macro
' Macro recorded 5/08/2004 by John Young
Dim rowcount As Integer
Dim columncount As Integer
Dim cellcountdown As Integer
Dim cellcountacross As Integer

Sheets("g419015_2_lf6_intersect_summari").Activate

Range("a2", Range("a2").End(xlDown)).Select
rowcount = Selection.Rows.Count

Range("g1", Range("g1").End(xlToRight)).Select
columncount = Selection.Columns.Count


For cellcountdown = 2 To (rowcount + 1)

For cellcountacross = 1 To columncount

'Cells(cellcountdown, (cellcountacross +
6)).VALUE = "=VLOOKUP(RC[-
1],'[BHSTStateRegister_TESTJY.xls]Broad Hydrological Soil
Types'!R2C1:R201C63,2,FALSE)"
'Cells(cellcountdown, (cellcountacross +
6)).VALUE = "=VLOOKUP(RC[-
1],'[BHSTStateRegister_TESTJY.xls]Broad Hydrological Soil
Types'!R2C1:R201C63,2,FALSE)"
Cells(cellcountdown, (cellcountacross + 6)).VALUE
= "=VLOOKUP(RC[-1],'[BHSTStateRegister_TESTJY.xls]Broad
Hydrological Soil Types'!R2C1:R201C63,RC[1],FALSE)"

Next cellcountacross

Next cellcountdown



Range("A2").Select
End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Vlookup - column index number - create as variable

Sorry, didn't see you code down below. I won't try to get inside that, but
for the simple example at the top

for variable = 1 to 10
cells(variable,1).Formula = "=vlookup(Sheet3!a1,Sheet3!a5:j10," & _
Variable & ",0)"
next variable

your look up range has to have at least as many columns as the nth column
you use for the 3rd argument.

--
Regards,
Tom Ogilvy



"Tom Ogilvy" wrote in message
...
=vlookup(a1,a5:f10,column(A1),0)

--
Regards,
Tom Ogilvy

"john young" wrote in message
...
I'm writing the following code to fill spreadsheets with
vlookup formulas. I can get the formula to be put in the
rows down & across that I need to fill, but what I want
to be able to do is create a variable so that the
col_index_num in the vlookup changes as the formula is
placed into that colum.

variable = 1 to 10
eg - =vlookup(a1,a5:f10,PUT VARIABLE HERE,0)
next variable

is this possible ????



Sub Macro20()
'
' Macro20 Macro
' Macro recorded 5/08/2004 by John Young
Dim rowcount As Integer
Dim columncount As Integer
Dim cellcountdown As Integer
Dim cellcountacross As Integer

Sheets("g419015_2_lf6_intersect_summari").Activate

Range("a2", Range("a2").End(xlDown)).Select
rowcount = Selection.Rows.Count

Range("g1", Range("g1").End(xlToRight)).Select
columncount = Selection.Columns.Count


For cellcountdown = 2 To (rowcount + 1)

For cellcountacross = 1 To columncount

'Cells(cellcountdown, (cellcountacross +
6)).VALUE = "=VLOOKUP(RC[-
1],'[BHSTStateRegister_TESTJY.xls]Broad Hydrological Soil
Types'!R2C1:R201C63,2,FALSE)"
'Cells(cellcountdown, (cellcountacross +
6)).VALUE = "=VLOOKUP(RC[-
1],'[BHSTStateRegister_TESTJY.xls]Broad Hydrological Soil
Types'!R2C1:R201C63,2,FALSE)"
Cells(cellcountdown, (cellcountacross + 6)).VALUE
= "=VLOOKUP(RC[-1],'[BHSTStateRegister_TESTJY.xls]Broad
Hydrological Soil Types'!R2C1:R201C63,RC[1],FALSE)"

Next cellcountacross

Next cellcountdown



Range("A2").Select
End Sub





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
How can I automatically update column index number in VLookup whe. Gene Excel Worksheet Functions 2 July 10th 12 11:23 AM
VLOOKUP Column Index Nate Excel Discussion (Misc queries) 5 March 5th 09 07:11 PM
vlookup column index number argument ibvalentine Excel Worksheet Functions 6 September 17th 07 04:26 PM
Can the column index in a cell address be made variable? cyberdude Excel Discussion (Misc queries) 1 November 20th 05 02:47 AM
Multiple Column Index Number in VLookup GorillaBoze Excel Worksheet Functions 8 October 28th 05 05:06 PM


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