Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Sue Sue is offline
external usenet poster
 
Posts: 285
Default Easier Way to Macro Total

Hi All

Is there an easier and shorter way than the macro below to add up every
third cell in column K

Sub Macro3()

Range("K3").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-1]C[-7]:R[1]C[-1])"
Range("K6").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-1]C[-7]:R[1]C[-1])"
Range("K9").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-1]C[-7]:R[1]C[-1])"
Range("K12").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-1]C[-7]:R[1]C[-1])"

End Sub

the next range would be K18 then K21, K24,K27,K30, thru to K144







--
Many Thanks

Sue
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default Easier Way to Macro Total

maybe something like this

Sub test()
Dim i As Long
Dim ws As Worksheet
Set ws = Worksheets("Sheet1")
For i = 3 To 21 Step 3
With ws.Range("K" & i)
.Formula = "=sum(" & .Offset(-1, -7).Address & ":" & _
.Offset(1, -1).Address & ")"
End With
Next
End Sub


--


Gary


"Sue" wrote in message
...
Hi All

Is there an easier and shorter way than the macro below to add up every
third cell in column K

Sub Macro3()

Range("K3").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-1]C[-7]:R[1]C[-1])"
Range("K6").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-1]C[-7]:R[1]C[-1])"
Range("K9").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-1]C[-7]:R[1]C[-1])"
Range("K12").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-1]C[-7]:R[1]C[-1])"

End Sub

the next range would be K18 then K21, K24,K27,K30, thru to K144







--
Many Thanks

Sue



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Easier Way to Macro Total

On Jun 13, 11:30 am, Sue wrote:
Hi All

Is there an easier and shorter way than the macro below to add up every
third cell in column K

Sub Macro3()

Range("K3").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-1]C[-7]:R[1]C[-1])"
Range("K6").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-1]C[-7]:R[1]C[-1])"
Range("K9").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-1]C[-7]:R[1]C[-1])"
Range("K12").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-1]C[-7]:R[1]C[-1])"

End Sub

the next range would be K18 then K21, K24,K27,K30, thru to K144

--
Many Thanks

Sue


Try this:

Sub SumBy3()
Dim i As Integer
Dim sumTot As Single

sumTot = Range("K3")
For i = 3 To 144 Step 3
sumTot = sumTot + Range("K3").Offset(i)
Next
Range("K145") = sumTot 'or whatever cell you want.

End Sub

SteveM
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Easier Way to Macro Total

Sub Macro3()
For i = 3 To 144 Step 3
Range("K" & i).FormulaR1C1 = "=SUM(R[-1]C[-7]:R[1]C[-1])"
Next
End Sub

--
Gary''s Student - gsnu200791
  #5   Report Post  
Posted to microsoft.public.excel.programming
Sue Sue is offline
external usenet poster
 
Posts: 285
Default Easier Way to Macro Total

Hi you Guys

Having fun trying all these answers and they all work OK -- brilliant all of
you
--
Many Thanks

Sue


"Gary Keramidas" wrote:

maybe something like this

Sub test()
Dim i As Long
Dim ws As Worksheet
Set ws = Worksheets("Sheet1")
For i = 3 To 21 Step 3
With ws.Range("K" & i)
.Formula = "=sum(" & .Offset(-1, -7).Address & ":" & _
.Offset(1, -1).Address & ")"
End With
Next
End Sub


--


Gary


"Sue" wrote in message
...
Hi All

Is there an easier and shorter way than the macro below to add up every
third cell in column K

Sub Macro3()

Range("K3").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-1]C[-7]:R[1]C[-1])"
Range("K6").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-1]C[-7]:R[1]C[-1])"
Range("K9").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-1]C[-7]:R[1]C[-1])"
Range("K12").Select
ActiveCell.FormulaR1C1 = "=SUM(R[-1]C[-7]:R[1]C[-1])"

End Sub

the next range would be K18 then K21, K24,K27,K30, thru to K144







--
Many Thanks

Sue




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
Is there an easier way? Alexey[_2_] Excel Worksheet Functions 4 September 28th 08 10:59 PM
easier way to do this? guitara Excel Discussion (Misc queries) 2 August 22nd 07 05:16 PM
Is there an easier way of doing this?? Andy Excel Programming 1 March 4th 06 12:04 AM
Is there an easier way? wmaughan Excel Discussion (Misc queries) 5 December 27th 05 10:56 PM
TextBox Macro - Is there an easier way ? Andrew B[_4_] Excel Programming 4 August 26th 05 05:10 AM


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