ok im new to this wesite and a new user of VBA
I have a column of numbers, that I don’t know the length in advance, but is located in column A. I want to write a subroutine that calculates the sum of the following
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-comfficeffice" /><o> </o>
Sum=1<SUP>st</SUP> number* last number+ 2<SUP>nd</SUP> number*next to last number + 3<SUP>rd</SUP> number* 3<SUP>rd</SUP> to last number etc. If the total number of numbers is odd, the middle number will have nothing to pair it with. In this case, square the middle number and add it to the sum. Note that the column contains only numbers and blank lines, and blank lines are found only after the column has ended.
i got the part on how to determine if the number is odd or even
Sub checkifevenorodd()
Dim userentry As Long
userentry = WorksheetFunction.CountA(Columns(1))
userentrydiv2 = CInt(userentry / 2)
userentrydiv2times2 = userentrydiv2 * 2
If userentrydiv2times2 = userentry Then
MsgBox ("even")
Else
MsgBox ("odd")
End If
End Sub
i appreciate any help
thank you
I have a column of numbers, that I don’t know the length in advance, but is located in column A. I want to write a subroutine that calculates the sum of the following
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-comfficeffice" /><o> </o>
Sum=1<SUP>st</SUP> number* last number+ 2<SUP>nd</SUP> number*next to last number + 3<SUP>rd</SUP> number* 3<SUP>rd</SUP> to last number etc. If the total number of numbers is odd, the middle number will have nothing to pair it with. In this case, square the middle number and add it to the sum. Note that the column contains only numbers and blank lines, and blank lines are found only after the column has ended.
i got the part on how to determine if the number is odd or even
Sub checkifevenorodd()
Dim userentry As Long
userentry = WorksheetFunction.CountA(Columns(1))
userentrydiv2 = CInt(userentry / 2)
userentrydiv2times2 = userentrydiv2 * 2
If userentrydiv2times2 = userentry Then
MsgBox ("even")
Else
MsgBox ("odd")
End If
End Sub
i appreciate any help
thank you