Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Excel Marco Fill Down Dynamic Range

Hello,

I am trying to run a vlookup through a macro but need the range to vary
depending on the numbers of rows of data (which will be different every
time).
Currently I have just used a fixed range in the code

Sub fillDownLookup()
Range("ah2").Select
ActiveCell.FormulaR1C1 =
"=VLOOKUP(RC[-13],Lookup!R2C6:R328C7,2,FALSE)"
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
Range("AH2:AH4000").Select
Selection.FillDown
End Sub

I would appreciate any advice of sugguestions that would replace the
fixed "Range("AH2:AH4000")" with code for a dynamic range

cheers
R

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 644
Default Excel Marco Fill Down Dynamic Range

Range("AH2:AH" & Range("AG" & Rows.Count).End(xlUp).Row).Select
Of course this assumes that you have data in AG4000 (or whatever the
last row happens to be in.) If not all columns contain data in every
row, then use this function to return the last used row:
Function LastRow() As Long
LastRow = Cells.Find(What:="*", After:=[A1], _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row
End Function
Then use:
Range("AH2:AH" & LastRow).Select

HTH

Charles Chickering

wrote:
Hello,

I am trying to run a vlookup through a macro but need the range to vary
depending on the numbers of rows of data (which will be different every
time).
Currently I have just used a fixed range in the code

Sub fillDownLookup()
Range("ah2").Select
ActiveCell.FormulaR1C1 =
"=VLOOKUP(RC[-13],Lookup!R2C6:R328C7,2,FALSE)"
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
Range("AH2:AH4000").Select
Selection.FillDown
End Sub

I would appreciate any advice of sugguestions that would replace the
fixed "Range("AH2:AH4000")" with code for a dynamic range

cheers
R


  #3   Report Post  
Posted to microsoft.public.excel.programming
ra ra is offline
external usenet poster
 
Posts: 27
Default Excel Marco Fill Down Dynamic Range

Absolutely perfect. thanks!

Die_Another_Day wrote:
Range("AH2:AH" & Range("AG" & Rows.Count).End(xlUp).Row).Select
Of course this assumes that you have data in AG4000 (or whatever the
last row happens to be in.) If not all columns contain data in every
row, then use this function to return the last used row:
Function LastRow() As Long
LastRow = Cells.Find(What:="*", After:=[A1], _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row
End Function
Then use:
Range("AH2:AH" & LastRow).Select

HTH

Charles Chickering

wrote:
Hello,

I am trying to run a vlookup through a macro but need the range to vary
depending on the numbers of rows of data (which will be different every
time).
Currently I have just used a fixed range in the code

Sub fillDownLookup()
Range("ah2").Select
ActiveCell.FormulaR1C1 =
"=VLOOKUP(RC[-13],Lookup!R2C6:R328C7,2,FALSE)"
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
Range("AH2:AH4000").Select
Selection.FillDown
End Sub

I would appreciate any advice of sugguestions that would replace the
fixed "Range("AH2:AH4000")" with code for a dynamic range

cheers
R


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
Help with copying dynamic column selected based on remote cell value and dynamic formula fill ers Charts and Charting in Excel 0 March 1st 06 01:05 AM
Help with copying dynamic column selected based on remote cell value and dynamic formula fill ers Excel Programming 0 March 1st 06 01:05 AM
ListBox "dynamic fill range" TK Excel Programming 3 September 10th 04 07:07 AM
automatic data fill , based on list into dynamic range dave h Excel Programming 1 August 25th 04 09:37 AM
Excel 2000 VBA - Set Print Range in dynamic range sub_pop[_5_] Excel Programming 2 July 27th 04 08:01 PM


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