VBA Stock movement summary

jimmy1986

New Member
Joined
May 16, 2021
Messages
36
Office Version
  1. 365
Hello all,
I have a file for the stock movement summary.
On sheet 1 I have a table (name: Summary) to check stock in and out.
I use Xlooup to find the info from the table (name: ID) in sheet 2 and count the stock in and out from sheet 3 (table name IN) and 4 (table name Out).
Please help me some codes VBA.
-To transfer the formula in every column in the table (summary) to VBA
The formula is :
-=XLOOKUP([@Name],Table2[Name],Table2[PL]) ' column PL
-=XLOOKUP([@Name],Table2[Name],Table2[HE]) 'column HE
-=[@Name]&[@Color] 'column Name and color
-=SUMIFS(IN[IN],IN[Name and Color],[@[Name and Color]],IN[DATE],">="&$L$2,IN[DATE],"<="&$L$3) 'Column IN
-=SUMIFS(OUT[OUT],OUT[Name and Color],[@[Name and Color]],IN[DATE],">="&$L$2,IN[DATE],"<="&$L$3) 'Column OUT
-=[@IN]-[@OUT] 'Column Remain
Then make it appear as value.
So every time I change the name and color or delete the row, the formula still works and keeps the value appear.
I am really appreciated for any help.
TEST.xlsx
ABCDEFGHIJKLMNO
1
2From Date1/6/21
3To Date30/6/21
4
5
6NoNameColorPLHEDMCBMAXTBName and ColorINOUTRemain
71Name1BlueHTCD301.51.5Name1Blue15224231099
82Name1GreenHTCD301.51.5Name1Green42455343711
93Name2RedHTCD301.51.5Name2Red5434553453811
104Name2PinkHTCD301.51.5Name2Pink4234344200
115Name3BlueHTTM2023Name3Blue4234654169
126Name3GreenHTTM2023Name3Green534537653377
137Name4RedHTTM2023Name4Red4564654499
148Name4PinkHTTM2023Name4Pink3453763377
15
16
SUMMARY
Cell Formulas
RangeFormula
E7:E14E7=XLOOKUP([@Name],Table2[Name],Table2[PL])
F7:F14F7=XLOOKUP([@Name],Table2[Name],Table2[HE])
G7:G14G7=XLOOKUP([@Name],Table2[Name],Table2[DM])
H7:H14H7=XLOOKUP([@Name],Table2[Name],Table2[CB])
I7:I14I7=XLOOKUP([@HE],Table2[HE],Table2[MAX])
J7:J14J7=XLOOKUP([@DM],Table2[DM],Table2[TB])
K7:K14K7=[@Name]&[@Color]
L7:L14L7=SUMIFS(IN[IN],IN[Name and Color],[@[Name and Color]],IN[DATE],">="&$L$2,IN[DATE],"<="&$L$3)
M7:M14M7=SUMIFS(OUT[OUT],OUT[Name and Color],[@[Name and Color]],IN[DATE],">="&$L$2,IN[DATE],"<="&$L$3)
N7:N14N7=[@IN]-[@OUT]


TEST.xlsx
ABCDEFGHIJKLM
1
2
3ID
4
5
6NameColorPLHEDMCBMAXTBName and Color
7Name1HTCD301.51.5
8Name2HTCD301.51.5
9Name3HTTM2023
10Name4HTTM2023
11
12
13
14
ID

TEST.xlsx
BCDEFGHIJKLMN
2
3
4STOCK IN
5
6DATENameColorPLHeDMCBMAXTBName and ColorIN
71/6/21Name1BlueHTCD301.51.5Name1Blue1522
82/6/21Name1GreenHTCD301.52Name1Green4245
93/6/21Name2RedHTCD301.51.5Name2Red54345
104/6/21Name2PinkHTCD301.51Name2Pink4234
115/6/21Name3BlueHTCD301.51.5Name3Blue4234
126/6/21Name3GreenHTCD301.52Name3Green53453
137/6/21Name4RedHTCD301.51.5Name4Red4564
148/6/21Name4PinkHTCD301.51Name4Pink3453
15
16
IN
Cell Formulas
RangeFormula
L7:L14L7=[@Name]&[@Color]



TEST.xlsx
BCDEFGHIJKLMN
2
3STOCK OUT
4
5
6DATENameColorPLHeDMCBMAXTBName and ColorOUT
71/6/21Name1BlueHTCD301.51.5Name1Blue423
82/6/21Name1GreenHTCD301.52Name1Green534
93/6/21Name2RedHTCD301.51.5Name2Red534
104/6/21Name2PinkHTCD301.51Name2Pink34
115/6/21Name3BlueHTCD301.51.5Name3Blue65
126/6/21Name3GreenHTCD301.52Name3Green76
137/6/21Name4RedHTCD301.51.5Name4Red65
148/6/21Name4PinkHTCD301.51Name4Pink76
15
16
17
18
OUT
Cell Formulas
RangeFormula
L7:L14L7=[@Name]&[@Color]
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
I try this:

Option Explicit
Sub table()
Dim table As ListObject
Set table = ActiveSheet.ListObjects(1)
table.ListColumns("PL").DataBodyRange.Formula = "=XLOOKUP([@Name],Table2[Name],Table2[PL])"
End Sub

It works but I do not know how to paste value and I want every time I change the Data (such as : name, Color... ) the column auto update the value, not by clicking on Sub button.
 
Upvote 0

Forum statistics

Threads
1,215,734
Messages
6,126,542
Members
449,316
Latest member
sravya

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