I need a macro which will check if the component it is referencing is the only one in the row, so as in the picture, for the green row, it needs to check that all cells 2 through 10 are empty, then add the contents of G5 to a running total.
Capture.PNG
Moving to the next row and finding the first filled column are trivial, I'm just stumped on the single-component check.
At first I tried to use IsEmpty, as only cells with number are initialized, however, I then learned that IsEmpty doesn't work for ranges. If there a simple command/ line of code I can use?
g is the row number, i is the number of filled rows (54 in this case) and I used h to find the correct columns. If the code is messy, it's because I started using vba last week ^_^
Sub Fraction_Counter()
g = 5
Do While g < i
h = 7
If IsEmpty(Worksheets("Fractions").Cells(g, h)) Then
h = h + 1
ElseIf h = 7 And IsEmpty(Worksheets("Fractions").Range(cells(g,8),cells(g17))) Then
Worksheets("Front End").Cells((h + 7), 10) = Worksheets("Front End").Cells((h + 7), 10) + Worksheets("Fractions").Cells(g, h)
ElseIf h = 17 And IsEmpty(Worksheets("Fractions").Range(Cells(g, 7), Cells(g, 16))) Then
Worksheets("Front End").Cells(h + 7, 10) = Worksheets("Front End").Cells(h + 7, 10) + Worksheets("Fractions").Cells(g, h)
ElseIf IsEmpty(Worksheets("Fractions").Range(Cells(g, 7), Cells(g, h - 1))) And IsEmpty(Worksheets("Fractions").Range(Cells(g, h + 1), Cells(g, 17))) Then
Worksheets("Front End").Cells(h + 7, 10) = Worksheets("Front End").Cells(h + 7, 10) + Worksheets("Fractions").Cells(g, h)
Else
g = g + 1
End If
'g = g + 1
'Loop
End Sub
Cheers
Bookmarks