Forum

Macro to sum base o...
 
Notifications
Clear all

Macro to sum base on two Fields record criteria

8 Posts
2 Users
0 Reactions
80 Views
(@david_ng)
Posts: 310
Reputable Member
Topic starter
 

Help to write a VB to find out total numer of Carton box , total number pf pallet,  Gross Weight of the cargoes  and M3 of the cargoes lot  base on following fields extract from an Cargoes Export database file.

 

(1)

Cargoes Receivings Tag No  - Base on an unique receivings Tag No to calculate above

(2)

Cargoes Packing Tag No  - Base on an unique Cargoes packing Tag No to calculate above
 
Posted : 23/03/2017 11:07 pm
(@david_ng)
Posts: 310
Reputable Member
Topic starter
 

Can we use Sumif command in the macro?

 
Posted : 24/03/2017 3:02 am
(@sunnykow)
Posts: 1417
Noble Member
 

Hi David

Do you really need a macro? Can you settle for some formulas? Refer column F and G for my answers (based on the answer you supplied). Or do you only want the grand total for each?

I have no idea how to calculate the M3 and GW as you did not show how you got the figures.

Sunny

 
Posted : 24/03/2017 4:32 am
(@david_ng)
Posts: 310
Reputable Member
Topic starter
 

Thanks Sunny, the formula is  sufficient.

 
Posted : 24/03/2017 5:38 am
(@david_ng)
Posts: 310
Reputable Member
Topic starter
 

Sorry, Sunny  but can you help explain the meaning and logic for this formula used.

 
Posted : 24/03/2017 11:16 pm
(@sunnykow)
Posts: 1417
Noble Member
 

Hi David

The explanation is a bit long so hope you can understand Laugh

COLUMN F 

The formula consists of 2 parts.

 Part 1

COUNTIF($C$2:C2,C2) counts how many times the Cargoes Receivings Tag No appears.

As you copy the formula down, $C$2:C2 will expand to $C$2:Cxx and it will count more and more cells and will return the number of times the tag appears within the expanding range.

 Part 2

IF(COUNTIF($C$2:C2,C2)>1,0,1)

I use IF() to check whether the cell returns a value of more than 1 (i.e. duplicate)

If it is more than 1 (duplicate), then give the cell a 0.

COLUMN G

It uses the same logic as column F. The difference is to determine if it is a Carton Box or Pallet.

Since I know that C is Carton and P is Pallet and it can be found in the 14th position from the left (it is important that this position is constant otherwise the formula will fail), I then use the MID() function to get that character and append the required text using IF(). 

You can see the attached example for a complete breakdown on how they work.

Hope this helps.

Sunny 

 
Posted : 25/03/2017 12:54 am
(@david_ng)
Posts: 310
Reputable Member
Topic starter
 

Deeep Deeep thanks again Sunny.

 
Posted : 25/03/2017 2:26 am
(@david_ng)
Posts: 310
Reputable Member
Topic starter
 

Again very very clear explanation so I grasp the tricks how it works.

 
Posted : 25/03/2017 2:30 am
Share: