Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Recording a macro to copy into a series of variable ranges

I have formulas that i need to copy to fill the end of each of a set of data
ranges. The data is all in A1 to A500, with the ranges seperated by empty
rows. The ranges are of variable length. The formula is required in the A
column just where the blanks appear in the ranges.

Why can't I record a relative address macro that incorporates variable
ranges? I use the end-down-down keys when recording the macro.

Do I have to use a VBA script for something this simple?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 220
Default Recording a macro to copy into a series of variable ranges

I'm sure there's an easier way to do this but here's one way...


Sub Test()
Dim i As Range, iRng As Range
Dim iTop As String, iBot As String

Set iRng = Range("A1:A500")
iTop = "$A$1"

For Each i In iRng
If Len(i) = 0 Then
iBot = i.Offset(-1, 0).Address
i.Formula = "=SUM(" & iTop & ":" & iBot & ")"
iTop = i.Offset(1, 0).Address
End If
Next

End Sub


--
Dan

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Recording a macro to copy into a series of variable ranges

Thank you Dan. I guess Ineed to get a handle on VBA....



"Dan R." wrote:

I'm sure there's an easier way to do this but here's one way...


Sub Test()
Dim i As Range, iRng As Range
Dim iTop As String, iBot As String

Set iRng = Range("A1:A500")
iTop = "$A$1"

For Each i In iRng
If Len(i) = 0 Then
iBot = i.Offset(-1, 0).Address
i.Formula = "=SUM(" & iTop & ":" & iBot & ")"
iTop = i.Offset(1, 0).Address
End If
Next

End Sub


--
Dan


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Recording a macro to copy into a series of variable ranges


Here is also a link that helped me:

http://contextures.com/tiptech.html


"Dan R." wrote:

I'm sure there's an easier way to do this but here's one way...


Sub Test()
Dim i As Range, iRng As Range
Dim iTop As String, iBot As String

Set iRng = Range("A1:A500")
iTop = "$A$1"

For Each i In iRng
If Len(i) = 0 Then
iBot = i.Offset(-1, 0).Address
i.Formula = "=SUM(" & iTop & ":" & iBot & ")"
iTop = i.Offset(1, 0).Address
End If
Next

End Sub


--
Dan


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
Macro to COPY FORMULA BETWEEN RANGES Randy Excel Discussion (Misc queries) 1 May 13th 10 02:20 PM
Macro to Copy Var. Ranges to Var. Rows Cmims Excel Discussion (Misc queries) 0 November 3rd 09 08:33 PM
Using macro/vba to copy varying ranges of rows BCLivell Excel Discussion (Misc queries) 3 June 6th 07 02:52 PM
Counting variable ranges and auto-summing variable ranges Father Guido[_5_] Excel Programming 2 March 29th 06 04:07 AM
Copy variable ranges fron difernte shets optimus_1973 Excel Worksheet Functions 2 January 8th 06 04:39 AM


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

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"