I have a macro which identifies the difference of value between my second visible cell in column B and all my other visible cells in column B. Then the macro returns me the difference of value in the second visible cell in column K (in this case on the screenshot 52479,85 EUR)…
I would like that the macro automatically assigns the difference of value found (in this case 52479,85) by adding it at the existing value in the last cell in column B (in this case 556,32).
In order to do that: I added this line at the end of my code: Range("B" & LastRow).Formula = Range("B" & LastRow).Value + Range("K" & secondRow).Value However it does not work, the macro does not add the 52479 to the 556,32 in my last cell in column B.
Thanks a lot in advance for your help. Xavi
Sub differencetoassign()
Dim i As Long, counter As Long
Dim LastRow As Long
Dim secondcell As Range
Dim r As Range
Set r = ActiveCell
Dim secondRow As Long
LastRow = ActiveSheet.Range("B" & Rows.Count).End(xlUp).Row
Range("B1").Activate
For i = 2 To LastRow 'assuming a header row not to be counted
If r.Rows(i).EntireRow.Hidden = False Then counter = counter + 1
If counter = 2 Then
Set third secondcell= r.Cells(i, "A")
Exit For
End If
Next i
Debug.Print secondcell
Debug.Print LastRow
secondRow = secondcell.Row
Debug.Print secondRow
Range("B" & LastRow).Formula = Range("B" & LastRow).Value + Range("K" & secondRow).Value
End Sub

Range("B" & LastRow) = Range("B" & LastRow) + Range("K" & secondRow)- Damian