helloakshay
New Member
I am generating certain numbers for a table. I am trying to write a vba code for numbers to be added row wise and column wise.
For example i want the sum of values from c2 to n2 in o2
and then move to o3 Where it should add values from c3 to n3.
I know there is a very simple way of adding values on the sheet, but i am just trying to learn how we can do it in vba.
For example i want the sum of values from c2 to n2 in o2
and then move to o3 Where it should add values from c3 to n3.
I know there is a very simple way of adding values on the sheet, but i am just trying to learn how we can do it in vba.
Code:
Private Sub Command Button1_Click()
Dim ab1 As Range
Dim AB2 As Range
'Random numbers
For Each ab1 In Range("c2:n27")
ab1.Offset(0, 0).Value = Application.WorksheetFunction.RandBetween(325, 956)
Next ab1
'Adding Values
For Each AB2 In Range("o2:o27")
AB2.Offset(0, 0).Value = Application.WorksheetFunction.Sum(Range("C2: N2"))
'From this point how will i move to the next row c3:n3 to get value on O3 and so on
Next AB2