Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 36
Default Copy multiple formulas to used range

Is there a more efficient way to copy multiple formulas to the used range of
a worksheet? I may have as many as 15 formulas in row 2, and they may not
be in contiguous columns.

This is what I'm doing now.

Thanks,
Patti

Sub copyFormulas()

Dim lstRow As Long
Dim sourceRange As Range
Dim fillrange As Range

Range("e2").Formula = "=VALUE(D2)"
Range("g2").Formula = "=IF(ISBLANK(F2),""Check"",VALUE(F2))"
Range("h2").Formula = "=IF(A3=A2,IF(E3<G2,(E3+1)-G2,E3-G2),"" "")"

lstRow = Cells(Rows.Count, "A").End(xlUp).Row

Set sourceRange = ActiveSheet.Range("e2")
Set fillrange = ActiveSheet.Range("e2:e" & lstRow)
sourceRange.AutoFill Destination:=fillrange

Set sourceRange = ActiveSheet.Range("g2")
Set fillrange = ActiveSheet.Range("g2:g" & lstRow)
sourceRange.AutoFill Destination:=fillrange

Set sourceRange = ActiveSheet.Range("h2")
Set fillrange = ActiveSheet.Range("h2:h" & lstRow)
sourceRange.AutoFill Destination:=fillrange

End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Copy multiple formulas to used range

I'd just fill the range:

Sub copyFormulas()

Dim lstRow As Long
lstRow = Cells(Rows.Count, "A").End(xlUp).Row

ActiveSheet.Range("e2:e" & lstRow).formula _
= "=VALUE(D2)"

ActiveSheet.Range("g2:g" & lstRow).Formula _
= "=IF(ISBLANK(F2),""Check"",VALUE(F2))"

ActiveSheet.Range("h2:h" & lstRow).Formula _
= "=IF(A3=A2,IF(E3<G2,(E3+1)-G2,E3-G2),"" "")"

End Sub


Patti wrote:

Is there a more efficient way to copy multiple formulas to the used range of
a worksheet? I may have as many as 15 formulas in row 2, and they may not
be in contiguous columns.

This is what I'm doing now.

Thanks,
Patti

Sub copyFormulas()

Dim lstRow As Long
Dim sourceRange As Range
Dim fillrange As Range

Range("e2").Formula = "=VALUE(D2)"
Range("g2").Formula = "=IF(ISBLANK(F2),""Check"",VALUE(F2))"
Range("h2").Formula = "=IF(A3=A2,IF(E3<G2,(E3+1)-G2,E3-G2),"" "")"

lstRow = Cells(Rows.Count, "A").End(xlUp).Row

Set sourceRange = ActiveSheet.Range("e2")
Set fillrange = ActiveSheet.Range("e2:e" & lstRow)
sourceRange.AutoFill Destination:=fillrange

Set sourceRange = ActiveSheet.Range("g2")
Set fillrange = ActiveSheet.Range("g2:g" & lstRow)
sourceRange.AutoFill Destination:=fillrange

Set sourceRange = ActiveSheet.Range("h2")
Set fillrange = ActiveSheet.Range("h2:h" & lstRow)
sourceRange.AutoFill Destination:=fillrange

End Sub


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 36
Default Copy multiple formulas to used range

That is much better!

The method that I used was something I've seen suggested in the NG (though
not necessarily for multiple formulas). Your way is so much cleaner, it
leaves me wondering if there is ever a reason that one would want to use the
AutoFill at all.

Anyway, thanks for the help Dave.

Patti


"Dave Peterson" wrote in message
...
I'd just fill the range:

Sub copyFormulas()

Dim lstRow As Long
lstRow = Cells(Rows.Count, "A").End(xlUp).Row

ActiveSheet.Range("e2:e" & lstRow).formula _
= "=VALUE(D2)"

ActiveSheet.Range("g2:g" & lstRow).Formula _
= "=IF(ISBLANK(F2),""Check"",VALUE(F2))"

ActiveSheet.Range("h2:h" & lstRow).Formula _
= "=IF(A3=A2,IF(E3<G2,(E3+1)-G2,E3-G2),"" "")"

End Sub


Patti wrote:

Is there a more efficient way to copy multiple formulas to the used range
of
a worksheet? I may have as many as 15 formulas in row 2, and they may
not
be in contiguous columns.

This is what I'm doing now.

Thanks,
Patti

Sub copyFormulas()

Dim lstRow As Long
Dim sourceRange As Range
Dim fillrange As Range

Range("e2").Formula = "=VALUE(D2)"
Range("g2").Formula = "=IF(ISBLANK(F2),""Check"",VALUE(F2))"
Range("h2").Formula = "=IF(A3=A2,IF(E3<G2,(E3+1)-G2,E3-G2),"" "")"

lstRow = Cells(Rows.Count, "A").End(xlUp).Row

Set sourceRange = ActiveSheet.Range("e2")
Set fillrange = ActiveSheet.Range("e2:e" & lstRow)
sourceRange.AutoFill Destination:=fillrange

Set sourceRange = ActiveSheet.Range("g2")
Set fillrange = ActiveSheet.Range("g2:g" & lstRow)
sourceRange.AutoFill Destination:=fillrange

Set sourceRange = ActiveSheet.Range("h2")
Set fillrange = ActiveSheet.Range("h2:h" & lstRow)
sourceRange.AutoFill Destination:=fillrange

End Sub


--

Dave Peterson



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Copy multiple formulas to used range

Maybe to copy formats, too???

Patti wrote:

That is much better!

The method that I used was something I've seen suggested in the NG (though
not necessarily for multiple formulas). Your way is so much cleaner, it
leaves me wondering if there is ever a reason that one would want to use the
AutoFill at all.

Anyway, thanks for the help Dave.

Patti

"Dave Peterson" wrote in message
...
I'd just fill the range:

Sub copyFormulas()

Dim lstRow As Long
lstRow = Cells(Rows.Count, "A").End(xlUp).Row

ActiveSheet.Range("e2:e" & lstRow).formula _
= "=VALUE(D2)"

ActiveSheet.Range("g2:g" & lstRow).Formula _
= "=IF(ISBLANK(F2),""Check"",VALUE(F2))"

ActiveSheet.Range("h2:h" & lstRow).Formula _
= "=IF(A3=A2,IF(E3<G2,(E3+1)-G2,E3-G2),"" "")"

End Sub


Patti wrote:

Is there a more efficient way to copy multiple formulas to the used range
of
a worksheet? I may have as many as 15 formulas in row 2, and they may
not
be in contiguous columns.

This is what I'm doing now.

Thanks,
Patti

Sub copyFormulas()

Dim lstRow As Long
Dim sourceRange As Range
Dim fillrange As Range

Range("e2").Formula = "=VALUE(D2)"
Range("g2").Formula = "=IF(ISBLANK(F2),""Check"",VALUE(F2))"
Range("h2").Formula = "=IF(A3=A2,IF(E3<G2,(E3+1)-G2,E3-G2),"" "")"

lstRow = Cells(Rows.Count, "A").End(xlUp).Row

Set sourceRange = ActiveSheet.Range("e2")
Set fillrange = ActiveSheet.Range("e2:e" & lstRow)
sourceRange.AutoFill Destination:=fillrange

Set sourceRange = ActiveSheet.Range("g2")
Set fillrange = ActiveSheet.Range("g2:g" & lstRow)
sourceRange.AutoFill Destination:=fillrange

Set sourceRange = ActiveSheet.Range("h2")
Set fillrange = ActiveSheet.Range("h2:h" & lstRow)
sourceRange.AutoFill Destination:=fillrange

End Sub


--

Dave Peterson


--

Dave Peterson
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 to copy range without changing formulas? [email protected] Excel Discussion (Misc queries) 3 December 31st 06 10:01 PM
How copy a range o cells without adjusting formulas? Oliver Excel Discussion (Misc queries) 4 September 3rd 06 12:44 AM
How do I copy formulas but using the same range each time I copy Laffin Excel Worksheet Functions 2 June 22nd 06 04:17 PM
Excel copy formulas using non contiguous range Paul Moles Excel Discussion (Misc queries) 4 March 11th 06 11:07 PM
Range COPY function - how to copy VALUES and not formulas James Cooke Excel Programming 1 August 21st 03 07:04 PM


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