VBA Code Required

hrayani

Well-known Member
Joined
Jul 23, 2010
Messages
1,500
Office Version
  1. 2016
Platform
  1. Windows
Hello Friends,

I want to copy specific data in specific format from one worksheet to another (both worksheet in the same workbook)

Here is the short sample data

Running Orders New Style.xlsm
ABCDEFGHIJKLMNOPQRSTUV
2PO #REF #PO DATECustomerSupplierArticleQualityDyed or PrintedFiber ContentConstructionSIZEQTYUNITPO SHIP DATEACTUAL SHIP DATEREMARKSSAMPLINGPO # CONCATARTICLE CONCATEXTRA COLUMNVALUESTATUS
337742163329-Dec-21TEX 1MillsBed SetMicrofiber Satin - 100 GsmDisperse Print100% Polyester75D X 200D 107X66Normal143,760Set(s)2-May-22OCT - 2021377421Bed Set$699,576In Process
437742263329-Dec-21TEX 1MillsPillow PairMicrofiber Satin - 100 GsmDisperse Dyed + Dispers Print100% Polyester75D X 200D 107X66Multiple233,544Pair(s)2-May-22OCT - 2021377421 - 377422Bed Set - Pillow Pair$452,181In Process
537742363329-Dec-21TEX 1MillsBed SetMicrofiber Satin - 100 GsmDisperse Print100% Polyester75D X 200D 107X66Over94,240Set(s)2-May-22OCT - 2021377421 - 377422 - 377423Bed Set - Pillow Pair$673,612In Process
637742463329-Dec-21TEX 1MillsBed SetMicrofiber Satin - 100 GsmDisperse Print100% Polyester75D X 200D 107X66King37,110Set(s)2-May-22OCT - 2021377421 - 377422 - 377423 - 377424Bed Set - Pillow Pair$309,762In Process
737742563329-Dec-21TEX 1MillsSide PillowMicrofiber Satin - 100 GsmDisperse Dyed + Dispers Print100% Polyester75D X 200D 107X6640x145176,532Pc(s)2-May-22OCT - 2021377421 - 377422 - 377423 - 377424 - 377425Bed Set - Pillow Pair - Side Pillow$307,166In Process
898015463410-Dec-21TEX 1MillsBed SetMicrofiber Satin - 100 GsmDisperse Print100% Polyester75D X 200D 107X66Normal59,976Set(s)6-Jun-22OCT - 2021980154Bed Set$249,122In Process
998015563410-Dec-21TEX 1MillsBed SetMicrofiber Satin - 100 GsmDisperse Print100% Polyester75D X 200D 107X66King25,410Set(s)6-Jun-22OCT - 2021980154 - 980155Bed Set$170,777In Process
1098015663410-Dec-21TEX 1MillsBed SetMicrofiber Satin - 100 GsmDisperse Print100% Polyester75D X 200D 107X66Over47,976Set(s)6-Jun-22OCT - 2021980154 - 980155 - 980156Bed Set$254,075In Process
1198015763410-Dec-21TEX 1MillsPillow PairMicrofiber Satin - 100 GsmDisperse Print100% Polyester75D X 200D 107X66Multiple51,240Pair(s)6-Jun-22OCT - 2021980154 - 980155 - 980156 - 980157Bed Set - Pillow Pair$ 41,313In Process
1212345663510-Dec-21ROS 2UsmanFitted SheetCTN Jersey - 135 GsmReactive Dyed100% Cotton30'S Cotton100x2003,920Pc(s)13-Feb-22Best Price & Easy Sleep - Contract # 21176967123456Fitted Sheet$ 14,896Shipped
1312345763510-Dec-21ROS 2UsmanFitted SheetCTN Jersey - 135 GsmReactive Dyed100% Cotton30'S Cotton150x2002,400Pc(s)13-Feb-22Best Price & Easy Sleep - Contract # 21176967123456 - 123457Fitted Sheet$ 12,960Shipped
1422998863614-Dec-21LOSFabricsSheet SetCTN Renforce - 100 GsmPigment Printed Rotary100% Cotton30X30 / 76X50Single1,416Set(s)28-Feb-22229988Sheet Set$ 14,168In Process
1522990063614-Dec-21LOSFabricsSheet SetCTN Renforce - 100 GsmPigment Printed Rotary100% Cotton30X30 / 76X50Single3,456Set(s)28-Feb-22229988 - 229900Sheet Set$ 41,437In Process
1640317563721-Dec-21OFFTowelTerry Beach TowelCTN 320 GSMReactive Print100% Cotton70x150 cm60,160Pc(s)18-Apr-22Amount in euro increased to 13%403175Terry Beach Towel$205,982In Process
1740317663721-Dec-21OFFTowelPonchoCTN 320 GSMReactive Print100% Cotton60x120 cm56,092Pc(s)18-Apr-22Amount in euro increased to 13%403175 - 403176Terry Beach Towel - Poncho$205,998In Process
183100886387-Jan-22OFFTowelTerry TowelCTN 385 GSMReactive Dyed100% Cotton50x100 cm (2 Pc Set)142,566Set(s)10-Jun-22Young Living ▬ Amount in euro increased to 14%310088Terry Towel$367,307Shipped
193100896387-Jan-22OFFTowelTerry TowelCTN 385 GSMReactive Dyed100% Cotton70x140 cm124,382Pc(s)10-Jun-22Young Living ▬ Amount in euro increased to 14%310088 - 310089Terry Towel$314,786Shipped
2056789163912-Jan-22ROS 2UsmanFitted SheetCTN Jersey - 135 GsmReactive Dyed100% Cotton30'S Cotton100x2004,080Pc(s)13-May-22Best Price & Easy Sleep - Contract # 21176967567891Fitted Sheet$ 15,504Shipped
2156789263912-Jan-22ROS 2UsmanFitted SheetCTN Jersey - 135 GsmReactive Dyed100% Cotton30'S Cotton150x2002,220Pc(s)13-May-22Best Price & Easy Sleep - Contract # 21176967567891 - 567892Fitted Sheet$ 11,988Shipped
2212987564012-Jan-22ROS 2UsmanFitted SheetCTN Jersey - 135 GsmReactive Dyed100% Cotton30'S Cotton100x2003,840Pc(s)1-Jun-22Best Price & Easy Sleep - Contract # 21176967129875Fitted Sheet$ 14,592Shipped
2312987664012-Jan-22ROS 2UsmanFitted SheetCTN Jersey - 135 GsmReactive Dyed100% Cotton30'S Cotton150x2002,400Pc(s)1-Jun-22Best Price & Easy Sleep - Contract # 21176967129875 - 129876Fitted Sheet$ 12,960Shipped
ORDERS
Cell Formulas
RangeFormula
R3:R23R3=IF(ISBLANK(B3),"",IF(B3<>B2,A3,IF(ISNUMBER(SEARCH(A3,R2)),R2,R2&" - "&A3)))
S3:S23S3=IF(ISBLANK(B3),"",IF(B3<>B2,F3,IF(ISNUMBER(SEARCH(F3,S2)),S2,S2&" - "&F3)))


Sheet 1: Copy from Sheet ORDERS
Sheet2: Copy to Sheet RUNNING ORDER STATUS

I want the data to copied to sheet 2 with following conditions

1) Copy all rows showing "In Process" in Column V from sheet 1 to sheet 2 starting from cell B4
Columns to copy would be A,B,C,D,E,F,G,K,L,M,N & P (Total 12 Columns)

2) Sort Data - 1st by Customer in Alphabetical order then by Ascending order PO ship date

3) Insert a Line when a Ref # changes
a) On the inserted Line: Show 1st instance for columns PO #, REF #, PO Date, Customer, Supplier, Article, Quality, PO Shape Date Columns
b) On the inserted Line: Show "Multiple" if more than one entry is found for Size, Unit & Remarks Columns else show 1st Instance
c) On the inserted Line: Show Total for the Qty Column

4) In Column A add value 1 to all the copied rows & value 2 to all the inserted rows (This is because I will be filtering records further)

5) Content Banding When a Ref # Changes

6) Dark grey color to the Inserted Rows

So, the final look will be like this

Running Orders New Style.xlsm
ABCDEFGHIJKLM
4PO #REF #PO DATECustomerSupplierArticleQualitySIZEQTYUNITPO SHIP DATEREMARKS
5137742163329-Dec-21TEX 1MillsBed SetMicrofiber Satin - 100 GsmNormal143,760Set(s)2-May-22
6137742263329-Dec-21TEX 1MillsPillow PairMicrofiber Satin - 100 GsmMultiple233,544Pair(s)2-May-22
7137742363329-Dec-21TEX 1MillsBed SetMicrofiber Satin - 100 GsmOver94,240Set(s)2-May-22
8137742463329-Dec-21TEX 1MillsBed SetMicrofiber Satin - 100 GsmKing37,110Set(s)2-May-22
9137742563329-Dec-21TEX 1MillsSide PillowMicrofiber Satin - 100 Gsm40x145176,532Pc(s)2-May-22
10237742163329-Dec-22TEX 1MillsBed SetMicrofiber Satin - 100 GsmMultiple685,186Multiple2-May-22
11198015463410-Dec-21TEX 1MillsBed SetMicrofiber Satin - 100 GsmNormal59,976Set(s)6-Jun-22
12198015563410-Dec-21TEX 1MillsBed SetMicrofiber Satin - 100 GsmKing25,410Set(s)6-Jun-22
13198015663410-Dec-21TEX 1MillsBed SetMicrofiber Satin - 100 GsmOver47,976Set(s)6-Jun-22
14198015763410-Dec-21TEX 1MillsPillow PairMicrofiber Satin - 100 GsmMultiple51,240Pair(s)6-Jun-22
15298015463410-Dec-22TEX 1MillsBed SetMicrofiber Satin - 100 GsmMultiple184,602Multiple6-Jun-22
16122998863614-Dec-21LOSFabricsSheet SetCTN Renforce - 100 GsmSingle1,416Set(s)28-Feb-22
17122990063614-Dec-21LOSFabricsSheet SetCTN Renforce - 100 GsmSingle3,456Set(s)28-Feb-22
18222998863614-Dec-22LOSFabricsSheet SetCTN Renforce - 100 GsmSingle4,872Set(s)28-Feb-22
19140317563721-Dec-21OFFTowelTerry Beach TowelCTN 320 GSM70x150 cm60,160Pc(s)18-Apr-22Amount in euro increased to 13%
20140317663721-Dec-21OFFTowelPonchoCTN 320 GSM60x120 cm56,092Pc(s)18-Apr-22Amount in euro increased to 13%
21240317563721-Dec-22OFFTowelTerry Beach TowelCTN 320 GSMMultiple116,252Pc(s)18-Apr-22
22137742163329-Dec-21TEX 1MillsBed SetMicrofiber Satin - 100 GsmNormal143,760Set(s)2-May-22
23137742263329-Dec-21TEX 1MillsPillow PairMicrofiber Satin - 100 GsmMultiple233,544Pair(s)2-May-22
24137742363329-Dec-21TEX 1MillsBed SetMicrofiber Satin - 100 GsmOver94,240Set(s)2-May-22
25137742463329-Dec-21TEX 1MillsBed SetMicrofiber Satin - 100 GsmKing37,110Set(s)2-May-22
26137742563329-Dec-21TEX 1MillsSide PillowMicrofiber Satin - 100 Gsm40x145176,532Pc(s)2-May-22
27237742163329-Dec-22TEX 1MillsBed SetMicrofiber Satin - 100 GsmMultiple685,186Multiple2-May-22
28198015463410-Dec-21TEX 1MillsBed SetMicrofiber Satin - 100 GsmNormal59,976Set(s)6-Jun-22
29198015563410-Dec-21TEX 1MillsBed SetMicrofiber Satin - 100 GsmKing25,410Set(s)6-Jun-22
30198015663410-Dec-21TEX 1MillsBed SetMicrofiber Satin - 100 GsmOver47,976Set(s)6-Jun-22
31198015763410-Dec-21TEX 1MillsPillow PairMicrofiber Satin - 100 GsmMultiple51,240Pair(s)6-Jun-22
32298015463410-Dec-22TEX 1MillsBed SetMicrofiber Satin - 100 GsmMultiple184,602Multiple6-Jun-22
RUNNING ORDER STATUS


Any help would be appreciated,

Regards,

Humayun
 
Last edited:
If it works, then the approach is right. :)
Thanks :)

Please!, one last question & then I am done with the project

Is it possible to concatenate (join with comma separated) unique values ?
Currently this is the part of last code which you have sent me for count unique which works PERFECTLY FINE

Excel Formula:
Set rng = .Range("K" & fRow & ":K" & lRow)
                Set dic = CreateObject("Scripting.Dictionary")
                For Each cel In rng
                    If Not dic.exists(cel.Value) Then
                        dic.Add cel.Value, Nothing
                    End If
                Next cel
                .Range("K" & lRow + 1) = dic.Count
 
Upvote 0

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Try:
VBA Code:
.Range("K" & lRow + 1) = Join(dic.keys, ", ")
 
Upvote 0

Forum statistics

Threads
1,214,845
Messages
6,121,902
Members
449,053
Latest member
Guy Boot

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