Need help in coding

taruna1986

New Member
Joined
Feb 8, 2022
Messages
35
Office Version
  1. 365
Hi Admin,

I have the attached data and I'm trying to find the correct macro coding for creating my journal. I want if the account number & company code subtotal are zero then the macro would display the account number, profit center, and company code with value in other columns for a journal. Please advise.

1702957692417.png
 
taruna let's keep the ball rolling, the question I have is, below should be your input and output. Now I believe by your description of what you want, shouldn't company code 300 account number 1110100031 should equal 0 but it's not in your final result. Is this by design or did you miss it? Anyway your problem is now in a usable form so we may get some more help. In the mean time I will try and come up with a macro.
Thank you so much for reviewing the issue@Ezguy4u The original data contains line items 13 and 14 as well for company code 300 account number 1110100031. These line items are preventing the subtotal of the account number and company code from being zero, which is why they are not appearing in the final results.
company code 300 account number 1110100031
1703022137069.xlsx
ABCDEFGHI
1Before: Original DataAfter: Final results
2Company codeAccount NumberAmountProfit CenterCompany codeAccount NumberAmountProfit Center
3100111010001110,0003000/P1200001100111010001110,0003000/P1200001
41001110100011-10,0003000/P63000011001110100011-10,0003000/P6300001
5100111010001103000/P6700001100111010001103000/P6700001
610011101000313,8573000/P405000130011101000116,0003000/P4200001
710011101000314,0003000/P50000013001110100011-6,0003000/P6600001
810011101000313,8003000/P500002320011101000316,0003000/P4150001
930011101000116,0003000/P42000012001110100031-6,0003000/P5000002
103001110100011-6,0003000/P6600001200111010003103000/P5000200
11300111010003110,0003000/P3400001
123001110100031-10,0003000/P4200001
1330011101000316,5003000/P5000015
1430011101000313,8003000/P5000202
1520011101000113,8573000/P4150001
1620011101000114,0003000/P6310001
1720011101000113,8003000/P7000001
1820011101000316,0003000/P4150001
192001110100031-6,0003000/P5000002
20200111010003103000/P5000200
Data
 
Upvote 0

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Ok I think I see it now. I am going to say the Account Number is the controlling factor. Second is the company code. If the amount adds up to zero, then it goes to the results table. Now it's getting late so I don't know if I can come up with anything tonight. I'll bet some of the A+ students might weigh in.
 
Upvote 0
Ok I think I see it now. I am going to say the Account Number is the controlling factor. Second is the company code. If the amount adds up to zero, then it goes to the results table. Now it's getting late so I don't know if I can come up with anything tonight. I'll bet some of the A+ students might weigh in.
I appreciate your clarity on the criteria. No rust at all. Feel free to take your time. Have a great evening.
 
Upvote 0
Sorry, I have been off-line since yesterday.

Since you are using Excel 365, I was hoping to be able make use of the new FILTER function. I thought maybe we could use SUMIFS in the condition to return just the value where the sum of all the Company/Account Number combinations add up to 0, but I am unable to get it to work.

I was trying to do something like this, but it is returning a #VALUE error for me.
Excel Formula:
=FILTER(A3:D20,SUMIFS($C$3:$C$20,$A$3:$A$20,$A3,$B$3:$B$20,$B3)=0)

1703167588353.png


Maybe that idea will spur someone else?
 
Upvote 0
I want to post the original problem using XL2BB

23-12-20 rev b.xlsm
ABCDEFGHI
1Before: Original DataAfter: Final results
2Company codeAccount NumberAmountProfit CenterCompany codeAccount NumberAmountProfit Center
3100111010001110,0003000/P1200001100111010001110,0003000/P1200001
420011101000113,8573000/P41500011001110100011-10,0003000/P6300001
530011101000116,0003000/P4200001100111010001103000/P6700001
61001110100011-10,0003000/P630000130011101000116,0003000/P4200001
720011101000114,0003000/P63100013001110100011-6,0003000/P6600001
83001110100011-6,0003000/P660000120011101000316,0003000/P4150001
9100111010001103000/P67000012001110100031-6,0003000/P5000002
1020011101000113,8003000/P7000001200111010003103000/P5000200
11300111010003110,0003000/P3400001
1210011101000313,8573000/P4050001
1320011101000316,0003000/P4150001
143001110100031-10,0003000/P4200001
1510011101000314,0003000/P5000001
162001110100031-6,0003000/P5000002
1730011101000316,5003000/P5000015
1810011101000313,8003000/P5000023
19200111010003103000/P5000200
2030011101000313,8003000/P5000202
Sheet1 (7)
 
Upvote 0
I want to post the original problem using XL2BB

23-12-20 rev b.xlsm
ABCDEFGHI
1Before: Original DataAfter: Final results
2Company codeAccount NumberAmountProfit CenterCompany codeAccount NumberAmountProfit Center
3100111010001110,0003000/P1200001100111010001110,0003000/P1200001
420011101000113,8573000/P41500011001110100011-10,0003000/P6300001
530011101000116,0003000/P4200001100111010001103000/P6700001
61001110100011-10,0003000/P630000130011101000116,0003000/P4200001
720011101000114,0003000/P63100013001110100011-6,0003000/P6600001
83001110100011-6,0003000/P660000120011101000316,0003000/P4150001
9100111010001103000/P67000012001110100031-6,0003000/P5000002
1020011101000113,8003000/P7000001200111010003103000/P5000200
11300111010003110,0003000/P3400001
1210011101000313,8573000/P4050001
1320011101000316,0003000/P4150001
143001110100031-10,0003000/P4200001
1510011101000314,0003000/P5000001
162001110100031-6,0003000/P5000002
1730011101000316,5003000/P5000015
1810011101000313,8003000/P5000023
19200111010003103000/P5000200
2030011101000313,8003000/P5000202
Sheet1 (7)

Ezguy4u- Have you just shared the snip of what I shared before or used the macro to get the final results​

 
Upvote 0
Sorry, I have been off-line since yesterday.

Since you are using Excel 365, I was hoping to be able make use of the new FILTER function. I thought maybe we could use SUMIFS in the condition to return just the value where the sum of all the Company/Account Number combinations add up to 0, but I am unable to get it to work.

I was trying to do something like this, but it is returning a #VALUE error for me.
Excel Formula:
=FILTER(A3:D20,SUMIFS($C$3:$C$20,$A$3:$A$20,$A3,$B$3:$B$20,$B3)=0)

View attachment 103903

Maybe that idea will spur someone else?
@Joe4 All good, thanks for taking out time to take a look.
 
Upvote 0
taruna here is my program to solve your problem. My programs tend to be big. Now it should work but if you find a problem let us know.

VBA Code:
Sub Prog06()

Dim LastRow As Long
Dim a As Long
Dim Row2 As Long
Dim Row As Long
Dim Row3 As Long

Row = 3
Row2 = 3
Row3 = 3

LastRow = Cells(Rows.Count, "A").End(xlUp).Row

Range("A2:D" & LastRow).Select
    ActiveWorkbook.ActiveSheet.Sort.SortFields.Clear
    ActiveWorkbook.ActiveSheet.Sort.SortFields.Add2 Key:=Range( _
        "A3:A" & LastRow), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
        xlSortNormal
    ActiveWorkbook.ActiveSheet.Sort.SortFields.Add2 Key:=Range( _
        "B3:B" & LastRow), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
        xlSortNormal
    With ActiveWorkbook.ActiveSheet.Sort
        .SetRange Range("A2:D" & LastRow)
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
    
  Do Until IsEmpty(Cells(Row, 1))

If Cells(Row, 2) = Cells(Row + 1, 2) And Cells(Row, 1) = Cells(Row + 1, 1) Then
    Cells(Row2, 11) = Cells(Row, 1)
    Cells(Row2, 12) = Cells(Row, 2)
    Cells(Row2, 13) = Cells(Row, 3)
    Cells(Row2, 14) = Cells(Row, 4)
Else
    Cells(Row2, 11) = Cells(Row, 1)
    Cells(Row2, 12) = Cells(Row, 2)
    Cells(Row2, 13) = Cells(Row, 3)
    Cells(Row2, 14) = Cells(Row, 4)
    Cells(Row2 + 1, 13).Formula = "=sum(M3:M" & Row2 & ")"
    
If Cells(Row2 + 1, 13) = 0 Then
    Range("K3:N" & Row2).Select
    Selection.Copy
    Range("F" & Row3).Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Range("K3:N" & Row2 + 1).Select
    Application.CutCopyMode = False
    Selection.Delete Shift:=xlToLeft
    
    Row3 = Cells(Rows.Count, "F").End(xlUp).Row + 1
    Row2 = 2
Else
    Range("K3:N" & Row2 + 1).Select
    Application.CutCopyMode = False
    Selection.Delete Shift:=xlToLeft
    
    Row2 = 2
   
   End If
    
    End If
    Row2 = Row2 + 1
    Row = Row + 1
    Range("A2").Select
Loop
    
    
Range("A2").Select

End Sub
 
Upvote 0
I forgot to add the screen updating option

VBA Code:
Sub Prog06()

Dim LastRow As Long
Dim a As Long
Dim Row2 As Long
Dim Row As Long
Dim Row3 As Long

Row = 3
Row2 = 3
Row3 = 3
Application.ScreenUpdating = False
LastRow = Cells(Rows.Count, "A").End(xlUp).Row

Range("A2:D" & LastRow).Select
    ActiveWorkbook.ActiveSheet.Sort.SortFields.Clear
    ActiveWorkbook.ActiveSheet.Sort.SortFields.Add2 Key:=Range( _
        "A3:A" & LastRow), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
        xlSortNormal
    ActiveWorkbook.ActiveSheet.Sort.SortFields.Add2 Key:=Range( _
        "B3:B" & LastRow), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
        xlSortNormal
    With ActiveWorkbook.ActiveSheet.Sort
        .SetRange Range("A2:D" & LastRow)
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
    
  Do Until IsEmpty(Cells(Row, 1))

If Cells(Row, 2) = Cells(Row + 1, 2) And Cells(Row, 1) = Cells(Row + 1, 1) Then
    Cells(Row2, 11) = Cells(Row, 1)
    Cells(Row2, 12) = Cells(Row, 2)
    Cells(Row2, 13) = Cells(Row, 3)
    Cells(Row2, 14) = Cells(Row, 4)
Else
    Cells(Row2, 11) = Cells(Row, 1)
    Cells(Row2, 12) = Cells(Row, 2)
    Cells(Row2, 13) = Cells(Row, 3)
    Cells(Row2, 14) = Cells(Row, 4)
    Cells(Row2 + 1, 13).Formula = "=sum(M3:M" & Row2 & ")"
    
If Cells(Row2 + 1, 13) = 0 Then
    Range("K3:N" & Row2).Select
    Selection.Copy
    Range("F" & Row3).Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Range("K3:N" & Row2 + 1).Select
    Application.CutCopyMode = False
    Selection.Delete Shift:=xlToLeft
    
    Row3 = Cells(Rows.Count, "F").End(xlUp).Row + 1
    Row2 = 2
Else
    Range("K3:N" & Row2 + 1).Select
    Application.CutCopyMode = False
    Selection.Delete Shift:=xlToLeft
    
    Row2 = 2
   
   End If
    
    End If
    Row2 = Row2 + 1
    Row = Row + 1
    Range("A2").Select
Loop
    
 Application.ScreenUpdating = True
Range("A2").Select

End Sub
 
Upvote 0

Forum statistics

Threads
1,215,203
Messages
6,123,627
Members
449,109
Latest member
Sebas8956

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top