Hi everyone,
I have coded a Macro where a user can decide which cell values belong together, these values should then be added in the next column. A maximum of 5 cells should be added together. The user should use characters in the second column to indicate which values belong together. If there is no indication, the original value of the left column should be just copied to the right column. Somehow, the code only recognizes only groups of 2- maybe someone can help?
Here is how it looks like when it breaks down:
Time user key in sum
0.021 0.021
0.163 a 0.654
0.491 a
0.050 0.050
0.067 b 0.186
0.119 b
0.023 b
0.097
0.044 c
0.041 c
0.032 d
0.004 d
0.001 d
0.012 d
0.001
0.018
Here is the code:
Sub manualstation()
Rem manual input of stations
Range("H3").Select
For j = 1 To 25
If ActiveCell.Text = "" Then
ActiveCell.Offset(0, 1) = ActiveCell.Offset(0, -1).Value
ActiveCell.Offset(1, 0).Select
Rem combine 5 processes
ElseIf ActiveCell.Text = ActiveCell.Offset(1, 0).Text = ActiveCell.Offset(2, 0).Text = ActiveCell.Offset(3, 0).Text = ActiveCell.Offset(4, 0).Text Then
ActiveCell.Offset(0, 1) = ActiveCell.Offset(0, -1).Value + ActiveCell.Offset(1, -1).Value + ActiveCell.Offset(2, -1).Value + ActiveCell.Offset(3, -1).Value + ActiveCell.Offset(4, -1).Value
ActiveCell.Offset(5, 0).Select
Rem combine 4 processes
ElseIf ActiveCell.Text = ActiveCell.Offset(1, 0).Text = ActiveCell.Offset(2, 0).Text = ActiveCell.Offset(3, 0).Text Then
ActiveCell.Offset(0, 1) = ActiveCell.Offset(0, -1).Value + ActiveCell.Offset(1, -1).Value + ActiveCell.Offset(2, -1).Value + ActiveCell.Offset(3, -1).Value
ActiveCell.Offset(4, 0).Select
Rem combine 3 processes
ElseIf ActiveCell.Text = ActiveCell.Offset(1, 0).Text = ActiveCell.Offset(2, 0).Text Then
ActiveCell.Offset(0, 1) = ActiveCell.Offset(0, -1).Value + ActiveCell.Offset(1, -1).Value + ActiveCell.Offset(2, -1).Value
ActiveCell.Offset(3, 0).Select
Rem combine 2 processes
ElseIf ActiveCell.Text = ActiveCell.Offset(1, 0).Text Then
ActiveCell.Offset(0, 1) = ActiveCell.Offset(0, -1).Value + ActiveCell.Offset(1, -1).Value
ActiveCell.Offset(2, 0).Select
End If
Next j
End Sub
Thank you so much for your help!
Bookmarks