PC Review


Reply
Thread Tools Rate Thread

AutoFill using a macro

 
 
katamy
Guest
Posts: n/a
 
      23rd Dec 2008
I’m working in Excel 2003. I have a report which runs in another program that
I save in Excel. I then create a macro to insert columns at various places
and perform a vlookup. The data varies each time the report is run. I know
there is a code that will allow me to AutoFill down to the last row of that
column, but I can’t remember how to do it. Any suggestions?

Here is the code…

Range("X2").Select
ActiveCell.FormulaR1C1 = _
"=VLOOKUP(RC[-1],'[Look up Vince report.xls]Function'!C1:C2,2,FALSE)"
Selection.AutoFill Destination:=Range("X2:X2649")
Range("X2:X2649").Select

Thanks in advance for your help!
 
Reply With Quote
 
 
 
 
Jim Rech
Guest
Posts: n/a
 
      23rd Dec 2008
This is one way to fill down the selection based on the column to the left:

With Selection
Range(.Offset(0, -1), .Offset(0, -1).End(xlDown)).Offset(0,
1).FillDown
End With


--
Jim
"katamy" <(E-Mail Removed)> wrote in message
news:6B34006A-27E0-4525-9CE4-(E-Mail Removed)...
| I’m working in Excel 2003. I have a report which runs in another program
that
| I save in Excel. I then create a macro to insert columns at various places
| and perform a vlookup. The data varies each time the report is run. I know
| there is a code that will allow me to AutoFill down to the last row of
that
| column, but I can’t remember how to do it. Any suggestions?
|
| Here is the code…
|
| Range("X2").Select
| ActiveCell.FormulaR1C1 = _
| "=VLOOKUP(RC[-1],'[Look up Vince
report.xls]Function'!C1:C2,2,FALSE)"
| Selection.AutoFill Destination:=Range("X2:X2649")
| Range("X2:X2649").Select
|
| Thanks in advance for your help!

 
Reply With Quote
 
Don Guillett
Guest
Posts: n/a
 
      23rd Dec 2008
Try it this way. Modify ranges to suit.

Sub makeformulaandfilldown()
lr = Cells(Rows.Count, "b").End(xlUp).Row
Range("e2:e" & lr).Formula = "=vlookup(b2,$c$2:$d$" & lr & ",2,false)"
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(E-Mail Removed)
"katamy" <(E-Mail Removed)> wrote in message
news:6B34006A-27E0-4525-9CE4-(E-Mail Removed)...
> I’m working in Excel 2003. I have a report which runs in another program
> that
> I save in Excel. I then create a macro to insert columns at various places
> and perform a vlookup. The data varies each time the report is run. I know
> there is a code that will allow me to AutoFill down to the last row of
> that
> column, but I can’t remember how to do it. Any suggestions?
>
> Here is the code…
>
> Range("X2").Select
> ActiveCell.FormulaR1C1 = _
> "=VLOOKUP(RC[-1],'[Look up Vince
> report.xls]Function'!C1:C2,2,FALSE)"
> Selection.AutoFill Destination:=Range("X2:X2649")
> Range("X2:X2649").Select
>
> Thanks in advance for your help!


 
Reply With Quote
 
Joel
Guest
Posts: n/a
 
      23rd Dec 2008
I used column W to determine the Last row of the worksheet. then I used a
simple copy to copy the formula from row 2 down to the last row

Range("X2").FormulaR1C1 = _
"=VLOOKUP(RC[-1],'[Look up Vincereport.xls]Function'!C1:C2,2,FALSE)"
lastRow = Range("W" & rows.count).end(xlup).Row
Range("X2").Copy _
Destination:=Range("X2:X" & LastRow)


"katamy" wrote:

> I’m working in Excel 2003. I have a report which runs in another program that
> I save in Excel. I then create a macro to insert columns at various places
> and perform a vlookup. The data varies each time the report is run. I know
> there is a code that will allow me to AutoFill down to the last row of that
> column, but I can’t remember how to do it. Any suggestions?
>
> Here is the code…
>
> Range("X2").Select
> ActiveCell.FormulaR1C1 = _
> "=VLOOKUP(RC[-1],'[Look up Vince report.xls]Function'!C1:C2,2,FALSE)"
> Selection.AutoFill Destination:=Range("X2:X2649")
> Range("X2:X2649").Select
>
> Thanks in advance for your help!

 
Reply With Quote
 
Michael
Guest
Posts: n/a
 
      24th Dec 2008
all you need is this if the last row never changes:
Range("X2:X2649").FormulaR1C1 = "=VLOOKUP(RC[-1],'[Look up Vince
report.xls]Function'!C1:C2,2,FALSE)"

If you need to find the last row do this:
ilastrow=Range("X65536").End(xlup).row
Range("X2:X" & ilastrow).FormulaR1C1 = "=VLOOKUP(RC[-1],'[Look up Vince
report.xls]Function'!C1:C2,2,FALSE)"



--
If this posting was helpful, please click on the Yes button.
Regards,

Michael Arch.




"katamy" wrote:

> I’m working in Excel 2003. I have a report which runs in another program that
> I save in Excel. I then create a macro to insert columns at various places
> and perform a vlookup. The data varies each time the report is run. I know
> there is a code that will allow me to AutoFill down to the last row of that
> column, but I can’t remember how to do it. Any suggestions?
>
> Here is the code…
>
> Range("X2").Select
> ActiveCell.FormulaR1C1 = _
> "=VLOOKUP(RC[-1],'[Look up Vince report.xls]Function'!C1:C2,2,FALSE)"
> Selection.AutoFill Destination:=Range("X2:X2649")
> Range("X2:X2649").Select
>
> Thanks in advance for your help!

 
Reply With Quote
 
PetLahev
Guest
Posts: n/a
 
      24th Dec 2008
Hi katamy

I assume that you need this

Note, for column "X"

Dim l_LastRow As Long

l_LastRow = Cells(Rows.Count, "X").End(xlUp).Row

Range("X2:X" & l_LastRow).FormulaR1C1 = "=VLOOKUP(RC[-1],'[Look up Vince
report.xls]Function'!C1:C2,2,FALSE)"
' but I prefer that
Range(Cells(2, "X"), Cells(l_LastRow, "X")).FormulaR1C1 =
"=VLOOKUP(RC[-1],'[Look up Vince report.xls]Function'!C1:C2,2,FALSE)"

Premek

"katamy" wrote:

> I’m working in Excel 2003. I have a report which runs in another program that
> I save in Excel. I then create a macro to insert columns at various places
> and perform a vlookup. The data varies each time the report is run. I know
> there is a code that will allow me to AutoFill down to the last row of that
> column, but I can’t remember how to do it. Any suggestions?
>
> Here is the code…
>
> Range("X2").Select
> ActiveCell.FormulaR1C1 = _
> "=VLOOKUP(RC[-1],'[Look up Vince report.xls]Function'!C1:C2,2,FALSE)"
> Selection.AutoFill Destination:=Range("X2:X2649")
> Range("X2:X2649").Select
>
> Thanks in advance for your help!

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Autofill Macro =?Utf-8?B?TGFjZXk=?= Microsoft Excel Programming 24 13th Mar 2007 09:54 PM
Re: Macro & Autofill Gord Dibben Microsoft Excel Discussion 1 1st Dec 2006 03:20 PM
AutoFill Macro eyeman6513_2000@yahoo.com Microsoft Excel Programming 8 19th Aug 2006 02:51 PM
Autofill macro Mike G Microsoft Excel Misc 6 21st Apr 2005 01:33 AM
autofill macro =?Utf-8?B?Z2xlZQ==?= Microsoft Excel Misc 1 14th Feb 2005 05:14 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:14 AM.