Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default Flexible autofill in macro


Hi.

I have a macro, that adds in two columns a value "Bestellijst" and "CTR".

After that I want the macro to autofill these values for every row in the
spreadsheet.

The number of rows vary. It could be 10, 346, 4659 or any other number.
When first recording the macro it stored the exact range at the time...
somthing like "C2:D3476" for this autofill.

I changed it already into the code below.
The problem now however... is that it autofills until the last row excell
can handle.
How can I get it to autofill only until the row with the last record each
time I run the macro, independant of the number of records?

---code---
Range("C2").Select
ActiveCell.FormulaR1C1 = "Bestellijst"
Range("D2").Select
ActiveCell.FormulaR1C1 = "CTR"
Range("C2:D2").Select
Selection.AutoFill Destination:=Range(Selection, Selection.End(xlDown))
---/code---

Thanks for your help.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,533
Default Flexible autofill in macro


Hi

I suppose you have data in column A, so we can use this column to determine
LastRow.

Also I removed the "Select" statements as they are not needed, and will slow
down your macro:

Dim LastRow As Long
LastRow = Range("A" & Rows.Count).End(xlUp).Row
Range("C2").FormulaR1C1 = "Bestellijst"
Range("D2").FormulaR1C1 = "CTR"
Range("C2:D2").AutoFill Destination:=Range("C2:D" & LastRow)

Hopes this helps.
....
Per

"Pluggie" skrev i meddelelsen
...
Hi.

I have a macro, that adds in two columns a value "Bestellijst" and "CTR".

After that I want the macro to autofill these values for every row in the
spreadsheet.

The number of rows vary. It could be 10, 346, 4659 or any other number.
When first recording the macro it stored the exact range at the time...
somthing like "C2:D3476" for this autofill.

I changed it already into the code below.
The problem now however... is that it autofills until the last row excell
can handle.
How can I get it to autofill only until the row with the last record each
time I run the macro, independant of the number of records?

---code---
Range("C2").Select
ActiveCell.FormulaR1C1 = "Bestellijst"
Range("D2").Select
ActiveCell.FormulaR1C1 = "CTR"
Range("C2:D2").Select
Selection.AutoFill Destination:=Range(Selection, Selection.End(xlDown))
---/code---

Thanks for your help.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default Flexible autofill in macro

Yes it did... Thanks a lot.

"Per Jessen" wrote:

Hi

I suppose you have data in column A, so we can use this column to determine
LastRow.

Also I removed the "Select" statements as they are not needed, and will slow
down your macro:

Dim LastRow As Long
LastRow = Range("A" & Rows.Count).End(xlUp).Row
Range("C2").FormulaR1C1 = "Bestellijst"
Range("D2").FormulaR1C1 = "CTR"
Range("C2:D2").AutoFill Destination:=Range("C2:D" & LastRow)

Hopes this helps.
....
Per

"Pluggie" skrev i meddelelsen
...
Hi.

I have a macro, that adds in two columns a value "Bestellijst" and "CTR".

After that I want the macro to autofill these values for every row in the
spreadsheet.

The number of rows vary. It could be 10, 346, 4659 or any other number.
When first recording the macro it stored the exact range at the time...
somthing like "C2:D3476" for this autofill.

I changed it already into the code below.
The problem now however... is that it autofills until the last row excell
can handle.
How can I get it to autofill only until the row with the last record each
time I run the macro, independant of the number of records?

---code---
Range("C2").Select
ActiveCell.FormulaR1C1 = "Bestellijst"
Range("D2").Select
ActiveCell.FormulaR1C1 = "CTR"
Range("C2:D2").Select
Selection.AutoFill Destination:=Range(Selection, Selection.End(xlDown))
---/code---

Thanks for your help.



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
Flexible X axis VBA/Macro generated duncan beech Charts and Charting in Excel 1 March 2nd 09 09:45 PM
Autofill in macro orquidea Excel Discussion (Misc queries) 5 November 21st 07 11:20 PM
How to call a macro with a flexible name Alex St-Pierre Excel Programming 2 November 23rd 06 10:39 PM
Making the macro more flexible? mariasa[_20_] Excel Programming 3 March 18th 06 06:50 AM
VBA - Flexible Sort Macro jordanctc[_10_] Excel Programming 2 August 26th 04 04:32 PM


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