Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Macro, autofill formula to end of column

I'm writing a macro that will insert a column, calculate a
formula and then fill the appropriate formula to the end
of the column. My problem is the column lentgh varies.
So I need to be able to reference a variable range. This
is what I have tried.

CNT = Range("B1", Range("B1").End(xlDown)).Count
Columns("A:A").Select
Selection.Insert Shift:=xlToRight
Range("A1").Select
ActiveCell.FormulaR1C1 = "run"
Range("A2").Select
ActiveCell.FormulaR1C1 = "=RC[1]"
Range("A3").Select
ActiveCell.FormulaR1C1 = "=IF(RC[1]<R[-1]C[1]+3,R[-1]C,RC
[1])"
Range("A3").Select
Selection.NumberFormat = "m/d/yy h:mm"
Selection.AutoFill Destination:=Range("A3:A249"),
Type:=xlFillDefault
Columns("A:A").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone,
SkipBlanks:= _
False, Transpose:=False

I have changed the range in this code ...

Selection.AutoFill Destination:=Range("A3:A249"),
Type:=xlFillDefault

to
Range("A3:A[cnt]")
and
RC:R[cnt]C
with no luck.

The column length is going to vary from 100 to 5000. I
don't want to set it to A5000 because the data is analyzed
further.

Thanks,
Monica


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Macro, autofill formula to end of column

Monica,

Try amending the code to read :-


CNT = Range("B1", Range("B1").End(xlDown)).Count
Debug.Print CNT

Columns("A:A").Select
Selection.Insert Shift:=xlToRight
Range("A1").Select
ActiveCell.FormulaR1C1 = "run"
Range("A2").Select
ActiveCell.FormulaR1C1 = "=RC[1]"
Range("A3").Select
ActiveCell.FormulaR1C1 = "=IF(RC[1]<R[-1]C[1]+3,R[-1]C,RC[1])"
Range("A3").Select
Selection.NumberFormat = "m/d/yy h:mm"
Selection.AutoFill Destination:=Range("A3", "a" & CNT)
Type:=xlFillDefault
Range("A3", "A" & CNT).Select
Selection.Copy
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone
SkipBlanks:=False, Transpose:=False




--
Message posted from http://www.ExcelForum.com

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Macro, autofill formula to end of column

Monica

Change
Range("A3:A[cnt]")
too range(cells(3,1),cells(cnt,1)

Regards
Peter
-----Original Message-----
I'm writing a macro that will insert a column, calculate

a
formula and then fill the appropriate formula to the end
of the column. My problem is the column lentgh varies.
So I need to be able to reference a variable range. This
is what I have tried.

CNT = Range("B1", Range("B1").End(xlDown)).Count
Columns("A:A").Select
Selection.Insert Shift:=xlToRight
Range("A1").Select
ActiveCell.FormulaR1C1 = "run"
Range("A2").Select
ActiveCell.FormulaR1C1 = "=RC[1]"
Range("A3").Select
ActiveCell.FormulaR1C1 = "=IF(RC[1]<R[-1]C[1]+3,R[-1]C,RC
[1])"
Range("A3").Select
Selection.NumberFormat = "m/d/yy h:mm"
Selection.AutoFill Destination:=Range("A3:A249"),
Type:=xlFillDefault
Columns("A:A").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlValues,

Operation:=xlNone,
SkipBlanks:= _
False, Transpose:=False

I have changed the range in this code ...

Selection.AutoFill Destination:=Range("A3:A249"),
Type:=xlFillDefault

to
Range("A3:A[cnt]")
and
RC:R[cnt]C
with no luck.

The column length is going to vary from 100 to 5000. I
don't want to set it to A5000 because the data is

analyzed
further.

Thanks,
Monica


.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Macro, autofill formula to end of column

Thanks worked like a charm!!!
-----Original Message-----
Monica

Change
Range("A3:A[cnt]")
too range(cells(3,1),cells(cnt,1)

Regards
Peter
-----Original Message-----
I'm writing a macro that will insert a column, calculate

a
formula and then fill the appropriate formula to the end
of the column. My problem is the column lentgh varies.
So I need to be able to reference a variable range.

This
is what I have tried.

CNT = Range("B1", Range("B1").End(xlDown)).Count
Columns("A:A").Select
Selection.Insert Shift:=xlToRight
Range("A1").Select
ActiveCell.FormulaR1C1 = "run"
Range("A2").Select
ActiveCell.FormulaR1C1 = "=RC[1]"
Range("A3").Select
ActiveCell.FormulaR1C1 = "=IF(RC[1]<R[-1]C[1]+3,R[-1]C,RC
[1])"
Range("A3").Select
Selection.NumberFormat = "m/d/yy h:mm"
Selection.AutoFill Destination:=Range("A3:A249"),
Type:=xlFillDefault
Columns("A:A").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlValues,

Operation:=xlNone,
SkipBlanks:= _
False, Transpose:=False

I have changed the range in this code ...

Selection.AutoFill Destination:=Range("A3:A249"),
Type:=xlFillDefault

to
Range("A3:A[cnt]")
and
RC:R[cnt]C
with no luck.

The column length is going to vary from 100 to 5000. I
don't want to set it to A5000 because the data is

analyzed
further.

Thanks,
Monica


.

.

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
Need Macro to autofill formula to last row with data Joe M. Excel Discussion (Misc queries) 4 January 22nd 10 07:54 PM
Automating to autofill column B based on column A entry GirlFridayCA Excel Discussion (Misc queries) 2 December 2nd 08 10:46 PM
Macro to autofill column [email protected] Excel Discussion (Misc queries) 1 June 21st 06 04:21 PM
Macro that will autofill a column with data, up to the last row of data in previous c Max Velocity Excel Programming 4 November 27th 03 10:34 AM
macro to autofill formula? Todd[_5_] Excel Programming 2 October 6th 03 07:10 PM


All times are GMT +1. The time now is 10:19 PM.

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"