-1
Hi, I’d like to ask you a question. My code is responsible for reading a column, if the value found is different from the previous one, it adds a row, paints a specific color and in the reference column writes "subtotal". My last task is to create the monthly summations on the line that has just been created. For this I used Formular1c1 but I could not get a logic to make this sum.
Here’s the excerpt from my code:
Sub criar_linha()
Dim txt As String
Dim endcell, total As Variant
Dim columnsRange As Range
txt = "Cliente"
endcell = ThisWorkbook.Worksheets("Teste").Cells.Find(txt, , ,xlWhole).Address
total = ThisWorkbook.Worksheets("Teste").Cells.Find("Total", , ,xlWhole).Column
Set columnsRange = Range(endcell, Range(endcell).End(xlDown)).Offset(1)
Dim cell As Range
Dim range_soma As Range
Dim cell_2 As Range
For Each cell In columnsRange
If cell.Value = "" Then
cell.Value = "Subtotal"
ElseIf cell.Value = "Subtotal" Then
ElseIf cell.Offset(1).Value <> cell.Value Then
MsgBox "insere abaixo " & cell.Address
cell.Offset(1).EntireRow.Insert
cell.Offset(1).Font.Bold = True
cell.Offset(1).Value = "Subtotal"
Range(cell.Offset(1, -2), cell.Offset(1, total - 4)).Interior.ColorIndex = 24
For Each cell_2 In Range(cell.Offset(1, 1), cell.Offset(1, total - 4))
cell_2.FormulaR1C1 = "=SUM(R[COUNT IF columnsRange = columnsRange*-1]C:R[-1]C)"
Next cell_2
End If
Next cell
End Sub
Thank you so much, Daniel! I was really caught up in that part.
– Alan Proença