Writing Excel VBA Code

Wetaka

New Member
Joined
Sep 1, 2018
Messages
3
Hullo,

I am Wetaka of Uganda, East Africa.

I Have started learning and using Excel VBA and I find your videos very Educative.

In my Data entry sheet invetory management i have been using the following formula and I would like write it in Excel VBA

How do we write the VBA code for the Formula: =MIN(SUMIF(I:I,I3,L:L)-SUMIF(I$1:I2,I3,O$1:O2),K3)

It finds the first items out of Stock.

Your help will be of great use

Thank you

Wetaka
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Welcome to the board. Try:
Code:
Sub M1()

    Dim s   As String
    Dim x   As Long
    
    x = Cells(Rows.Count, 9).End(xlUp).Row - 2
    s = "=MIN(SUMIF($I$1:$I$LR,I3,$L$1:$L$LR)-SUMIF(I$1:I2,I4,O$1:O2),K3)"
    s = Replace(s, "LR", x)
    
   Cells(3, Cells(3, Columns.Count).End(xlToLeft).Offset(, 1).Column).Resize(x).Formula = s
   
End Sub
 
Last edited:
Upvote 0
Hullo JackDanIce,

Thank you for your help.

I tried to use the code exactly as I received it ie,
Sub M1()

Dim s As String
Dim x As Long

x = Cells(Rows.Count, 9).End(xlUp).Row - 2
s = "=MIN(SUMIF($I$1:$I$LR,I3,$L$1:$L$LR)-SUMIF(I$1:I2,I4,O$1:O2),K3)"
s = Replace(s, "LR", x)

Cells(3, Cells(3, Columns.Count).End(xlToLeft).Offset(, 1).Column).Resize(x).Formula = s

End Sub

The results was the following formula in column K(Value Out)as in the table below




=MIN(SUMIF($I$1:$I$24,I3,$L$1:$L$24)-SUMIF(I$1:I2,I4,O$1:O2),K3)
every time I make an entry and submit the formula is inserted in the next column ie K, L M etc
When I made a few adjustments of the line
s = "=MIN(SUMIF($I$1:$I$LR,I3,$L$1:$L$LR)-SUMIF(I$1:I2,I4,O$1:O2),K3)" to s = "=MIN(SUMIF($D$1:$D$LR,D3,$F$1:$F$LR)-SUMIF(D$1:D2,D4,I$1:I2),E3)"
The following formula resulted on running the code in excel column K
=MIN(SUMIF($I$1:$I$24,I3,$L$1:$L$24)-SUMIF(I$1:I2,I4,O$1:O2),K3)

I expected to see the result similar to the fomula =MIN(SUMIF(D:D,D3,F:F)-SUMIF(D$1:D2,D3,I$1:I2),E3) when inserted in column I named FIFO Qty Out in the Table below.


Date
Request_Invoice Number
From_To
Item_NameQty_InQty_OutUnit_Cost
Value_Received
FIFOQtyOut
Balance InStoreValueOut
01/09/20187889 Books10
10
00
02/09/2018H788727 Pens0 000
02/09/2018H83737abc LtdPencils400 315850
09/02/201876662XYZ LtdBooks1000 010000
09/02/201876662Abc LtdRuled Papers100030300015850
09/04/2018gyuu766AdminBooks09000
000
09/04/2018
gyuu766SalesPencils09000000
pens1000 4960
09/09/20183029abc LtdChalk2000 301700
08/10/20184399Dpt QWBooks0400000
09/09/20183029dpt edParacetamol 500mg Tabs2000 02000
08/10/20184399salespens0400000
09/03/201832443rAdminPencils04000000
31/08/2018fdg4521AdminPencils02000000
30/08/201846732AdminPencils05000000
25/08/20182443wAdminPencils02000000
23/08/2018F6557AdminPencils01000000
24/08/2018wtt56788AdminPencils02500000
29/08/20187766712XYZ LtdBooks1000050500001548460
16/08/201888y77hAdminBooks015000000
15/08/2018783hAdminBooks02000000
17/08/201834SalesPencils06000000
25/08/201843321XYZ LtdRuled Papers8900504450008900
14/08/2018245ewAdminChalk03000000
20/08/20184533AdminRuled Papers0150000

<colgroup><col style="mso-width-source:userset;mso-width-alt:4681;width:96pt" width="128"> <col style="width:48pt" span="10" width="64"> </colgroup><tbody>
</tbody>

I Appreciate every effort to help me.

Thank you
 
Upvote 0

Forum statistics

Threads
1,215,152
Messages
6,123,323
Members
449,094
Latest member
Chestertim

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