Jyotirmaya
Board Regular
- Joined
- Dec 2, 2015
- Messages
- 216
- Office Version
- 2019
- Platform
- Windows
<tbody>
[TD="class: votecell"]
[/TD]
[TD="class: postcell"] I have Three Sheets in excel Sheet1 - Details of collection done in different heads as per user ID with receipt number and date, heads are sports pack, entertainment pack,regional pack Sheet2 - Dues of different users with their user ID in different head Sheet3 - In sheet 3,I want that the balance amount due of users with different head according to the user ID
In sheet 3 I need to calculate how much due left based on the User ID
I need a macro for this, Presently I am copying data of sheet2 then copying data of sheet1 then sorting the value as per USER ID and using the following code
[/TD]
</tbody>
Code:
<code>Sub try()
Dim c As Range
Dim lRow As Long
lRow = 1
Dim lRowLast As Long
Dim lRowDiff As Long
Dim lRowPortion As Long
lRowPortion = 1
Dim bFoundCollection As Boolean
With ActiveSheet
lRowLast = .Cells(.Rows.Count, 1).End(xlUp).Row
Do
Set c = .Range("A" & lRow)
If c.Value Like "*COLLECTION*" Then
bFoundCollection = True
ElseIf bFoundCollection Then
bFoundCollection = False
If c.Value <> "BALANCE" Then
c.EntireRow.Insert
lRowLast = lRowLast + 1
Set c = c.Offset(-1, 0)
c.Value = "BALANCE"
End If
If c.Value = "BALANCE" Then
.Range(c, c.Offset(0, 18)).Font.Color = RGB(0, 0, 0)
.Range(c, c.Offset(0, 18)).Interior.Color = RGB(200, 200, 200)
lRowDiff = c.Row - lRowPortion
.Range(c.Offset(0, 3), c.Offset(0, 18)).FormulaR1C1 = _
"=SUMIF(R[-" & lRowDiff & "]C1:RC1, ""*DEMAND*"", R[-" & lRowDiff & "]C:RC)" & _
"-SUMIF(R[-" & lRowDiff & "]C1:RC1, ""*COLLECTION*"", R[-" & lRowDiff & "]C:RC)"
lRowPortion = c.Row + 1
End If
End If
lRow = lRow + 1
Loop While lRow <= lRowLast + 1
End With
End Sub</code>
Sheet2
After Macro I am expecting this