LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 410
Default Macro to add Multiple columns

My code is below. It keeps throwing an error on the fist for each.
It says Next without for. Any help will be greatly appreciated.

Thanks,
Jay

Sub SumHKCdays()
Dim DataSht As Worksheet
Dim Start As Double
Dim LstRow As Long
Dim RngHD As Range
Dim RngKD As Range
Dim RngCD As Range
Dim Rng As Range
Dim i
Dim Dt As Double
Dim X As Double
Dim Target As Range
Set Target = Range("H3")
Set DataSht = Sheet22
LstRow = DataSht.Range("A1").SpecialCells(xlCellTypeLastCel l).Row
Set RngHD = DataSht.Range("A5:A" & LstRow)
Set RngKD = DataSht.Range("BC5:BC" & LstRow)
Set RngCD = DataSht.Range("CD5:CD" & LstRow)


Do Until Target.Roww = 32
If Target.Offset(0, -7) = "" Then
i = 0
Else
Start = Target.Offset(0, -7) - 13
Dt = Target.Offset(0, -7)

For Each i In RngHD
If i <= Dt And i = Start Then
X = X + i.Offset(0, 1) + i.Offset(0, 6) + i.Offset(0, 11)
+ _
i.Offset(0, 16) + i.Offset(0, 21) + i.Offset(0, 26) + _
i.Offset(0, 31) + i.Offset(0, 36) + i.Offset(0, 43) +
i.Offset(0, 48)
Else
X = X + 0
End
Next i

For Each i In RngKD
If i <= Dt And i = Start Then
X = X + i.Offset(0, 1) + i.Offset(0, 6) + i.Offset(0, 11)
+ _
i.Offset(0, 16) + i.Offset(0, 21) + i.Offset(0, 24)
Else
X = X + 0
End
Next i
For Each i In RngCD
If i <= Dt And i = Start Then
X = X + i.Offset(0, 1) + i.Offset(0, 4) + i.Offset(0, 7) +
_
i.Offset(0, 12)
Else
X = X + 0
End
Next i
End If
i = X
Loop

End Sub
 
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
I need a macro to transpose multiple columns A1-Z1, A2-X2 etc Wombat62 Excel Discussion (Misc queries) 7 September 18th 06 05:05 AM
Combine multiple columns into two long columns, Repeating rows in first column [email protected] Excel Discussion (Misc queries) 2 July 31st 06 09:45 PM
Combine multiple columns into two long columns, Repeating rows in first column [email protected] Excel Discussion (Misc queries) 0 July 31st 06 05:07 PM
macro to compile columns on multiple sheets simonsmith Excel Discussion (Misc queries) 2 May 9th 06 04:06 PM
Macro to align and compare multiple rows and columns Manav Ram via OfficeKB.com New Users to Excel 1 March 5th 05 12:38 AM


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