Home Sum every odd row in a single Column VBA
Reply: 0

Sum every odd row in a single Column VBA

user2024 Published in July 18, 2018, 4:49 am

I have a code that searches an excel fill for the word distance, takes the value of the cell next to it, paste it into a new cell, then sums all the cells up. Which works great, but i now need to find a way to only sum ever even row number. Does that make sense?

Sub Distance_Check()

Dim DistanceCheck As String

Dim DistanceNumber As String

Dim DistanceSum As String

Dim DistanceTotal As String

DistanceCheck = MsgBox("Would you like to check the distance?", vbYesNo)

If DistanceCheck = vbYes Then
If IsArray(fname) Then Workbooks.OpenText fname(1)

                        i = 1
                        findStr = "Distance"
                        Set foundCel = Range("A:A").Find(what:=findStr)
                        If Not foundCel Is Nothing Then
                            firstAddress = foundCel.Address
                                Range("J" & i).Value = foundCel.Offset(0, 1).Value
                                Set foundCel = Range("A:A").FindNext(foundCel)
                                i = i + 1
                            Loop While Not foundCel Is Nothing And foundCel.Address <> firstAddress
                        End If
                        Set wkbSourceBook = ActiveWorkbook

            DistanceNumber = i - 2

            DistanceSum = WorksheetFunction.Sum(Range(Cells(2, 15), (Cells(DistanceNumber + 1, 15))))
            DistanceTotal = DistanceSum / DistanceNumber

            If DistanceNumber = Cells(2, 12) Then
            MsgBox ("No error found wihin distance")
            MsgBox ("Error found with distance")
            End If
End If
Call Save_Data
End Sub

Would the way youd go about this be using a for loop on the


Where j = 0, j = j +2 , Until j > DistanceNumber,

Would that work? If so how would you go about it?


You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.316121 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO