VBA - Layout and sorting with conditions

BorisTheCat84

New Member
Joined
Apr 30, 2021
Messages
17
Office Version
  1. 2019
Platform
  1. Windows
Hi Team,

I'm facing the current scenario, I will start by placing the sheet that i'm working in and then bring up what has to be done:
Mr.Excel.xlsx
ABCDEFGHIJKL
1
2UUIDWhatsover1Whatsover2Whatsover3Whatsover4Whatsover5Whatsover6Whatsover7Whatsover8Whatsover9Adjust and filterWhatsover10
3140542WhatsoverWhatsoverWhatsoverWhatsoverWhatsover5/20/2021 10:00:00 AM5/20/2021 7:00:00 PMScheduledWhatsover3-Moderate/Limited
4WhatsoverWhatsoverWhatsoverWhatsoverOrangevrqm is great for taste
5WhatsoverWhatsoverWhatsoverWhatsoverOrangevrqm is really good
6WhatsoverWhatsoverWhatsoverWhatsoverOrange has good result
7Orange is really good
8OrangeVMGT0 are everywhere
9Orange is in my house
10Blueberry is really good
11Blueberry is really good.Blueberry is delicous
12BlueberryVMGT0 is really good.Blueberry is delicous1
13Blueberry is really good.Blueberry is delicous2
14Blueberry is reallyVMGT0 good.Blueberry is delicous3
15Blueberry is really good.Blueberry is delicous4
16Blueberry is really good.Blueberry is delicous5
17140555Whatsover5/20/2021 1:00:00 PM5/20/2021 3:00:00 PMDraftWhatsoverOrange is really good3-Moderate/Limited
18Orangeiwfm0 has good result
19Orange are everywhere
20140888Whatsover5/20/2021 1:00:00 PM5/20/2021 3:00:00 PMDraftWhatsoverOrangeiwfm0 is really good3-Moderate/Limited
21Orange has good result
22Orangeiwfm0 is really good
23May 20, 2021 8:35 AM
Sheet1


So Mainly a cleanup should be done in Column K:K respecting each UUID (in such not to apply the same condition on cells that belongs to the second UUID) according to the following criteria:
1- Clear Duplicates in the column
2- Clear all cells where "vrqm" or "VMGT0" or "wfm0" is not found in any word inside the cell // (note i have more but i will add them myself)
3- Shift cell up to avoid empty cells
4- Shift cell up in case the cell that matches the UUID is empty
5- Delete Empty Rows

Once that is done we will have to work on the entire table to properly format it, we will mainly need to merge empty cells in each column till they reach the line before the next UUID starts.
Finally, last task will be to merge and center the last row.

The expected output should be as follow:
UUIDWhatsover1Whatsover2Whatsover3Whatsover4Whatsover5Whatsover6Whatsover7Whatsover8Whatsover9Adjust and filterWhatsover10
140542WhatsoverWhatsoverWhatsoverWhatsoverWhatsover5/20/2021 10:00:00 AM5/20/2021 10:00:00 AMScheduledWhatsoverOrangevrqm is great for taste3-Moderate/Limited
WhatsoverWhatsoverWhatsoverWhatsover5/20/2021 10:00:00 AM5/20/2021 10:00:00 AMOrangevrqm is really good
WhatsoverWhatsoverWhatsoverWhatsoverOrange is really goodwfm0
WhatsoverWhatsoverWhatsoverWhatsoverOrangeVMGT0 are everywhere
BlueberryVMGT0 is really good.Blueberry is delicous
Blueberry is reallyVMGT0 good.Blueberry is delicous3
140555WhatsoverWhatsoverWhatsoverWhatsoverWhatsover5/20/2021 1:00:00 PM5/20/2021 3:00:00 PMDraftWhatsoverOrange is reallywfm0 good3-Moderate/Limited
Orangeiwfm0 has good result
140888WhatsoverWhatsoverWhatsoverWhatsoverWhatsover5/20/2021 1:00:00 PM5/20/2021 3:00:00 PMDraftWhatsoverOrangeiwfm0 is really good3-Moderate/Limited
WhatsoverWhatsoverWhatsoverWhatsover5/20/2021 1:00:00 PM5/20/2021 3:00:00 PM
May 20, 2021 8:35 AM


I would appreciate if you guys could help me with the VBA Code.

Cheers!
Boris
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Where is your data coming from? This is possible to do with VBA, but the steps you outlined seems to be MUCH easier to do with a few steps with Power Query.
1. Remove duplicates from 'Adjust and Filter' column
2. Filter only cells that contain the specified strings from 'Adjust and Filter' column
3. Fill down (on all the columns it's needed on)

With Power Query it is that it's literally a few button presses to get what you need and I'll argue it's less error-prone than a script in the long run. However, you will not be able to get the exact formatting you wanted (i.e. merging the cells like that).
 
Upvote 0
Where is your data coming from? This is possible to do with VBA, but the steps you outlined seems to be MUCH easier to do with a few steps with Power Query.
1. Remove duplicates from 'Adjust and Filter' column
2. Filter only cells that contain the specified strings from 'Adjust and Filter' column
3. Fill down (on all the columns it's needed on)

With Power Query it is that it's literally a few button presses to get what you need and I'll argue it's less error-prone than a script in the long run. However, you will not be able to get the exact formatting you wanted (i.e. merging the cells like that).
I do know that it can be done in VBA - it's not complicated // more complexe tasks were already built with VBA...
 
Upvote 0
If there's a specific reason you want/need to use VBA, by all means go for it; I was merely trying to propose an alternative already built into excel you might find useful that has also helped me out immensely when cleaning and transforming lots of data.

If you have some specific things in your VBA script you need help with I'd be happy to help you out.
 
Upvote 0
If there's a specific reason you want/need to use VBA, by all means go for it; I was merely trying to propose an alternative already built into excel you might find useful that has also helped me out immensely when cleaning and transforming lots of data.

If you have some specific things in your VBA script you need help with I'd be happy to help you out.
Thank you! - i'm aware of the Power Queries but we need the script to run with other macros as well...
Mainly what's needed is the code to the described scenario :)
 
Upvote 0
Small mistake // main table:
Mr.Excel.xlsx
ABCDEFGHIJKL
2UUIDWhatsover1Whatsover2Whatsover3Whatsover4Whatsover5Whatsover6Whatsover7Whatsover8Whatsover9Adjust and filterWhatsover10
3140542WhatsoverWhatsoverWhatsoverWhatsoverWhatsover5/20/2021 10:00:00 AM5/20/2021 7:00:00 PMScheduledWhatsover3-Moderate/Limited
4WhatsoverWhatsoverWhatsoverWhatsover5/21/2021 10:00:00 AM5/21/2021 10:00:00 AMOrangevrqm is great for taste
5WhatsoverWhatsoverWhatsoverWhatsoverOrangevrqm is really good
6WhatsoverWhatsoverWhatsoverWhatsoverOrange has good result
7Orange is really good
8OrangeVMGT0 are everywhere
9Orange is in my house
10Blueberry is really good
11Blueberry is really good.Blueberry is delicous
12BlueberryVMGT0 is really good.Blueberry is delicous1
13Blueberry is really good.Blueberry is delicous2
14Blueberry is reallyVMGT0 good.Blueberry is delicous3
15Blueberry is really good.Blueberry is delicous4
16Blueberry is really good.Blueberry is delicous5
17140555Whatsover5/20/2021 1:00:00 PM5/20/2021 3:00:00 PMDraftWhatsoverOrange is really good3-Moderate/Limited
18Orangeiwfm0 has good result
19Orange are everywhere
20140888Whatsover5/20/2021 1:00:00 PM5/20/2021 3:00:00 PMDraftWhatsoverOrangeiwfm0 is really good3-Moderate/Limited
21Orange has good result
22Orangeiwfm0 is really good
23May 20, 2021 8:35 AM
Sheet1


Expected output:
UUIDWhatsover1Whatsover2Whatsover3Whatsover4Whatsover5Whatsover6Whatsover7Whatsover8Whatsover9Adjust and filterWhatsover10
140542WhatsoverWhatsoverWhatsoverWhatsoverWhatsover5/20/2021 10:00:00 AM5/20/2021 10:00:00 AMScheduledWhatsoverOrangevrqm is great for taste3-Moderate/Limited
WhatsoverWhatsoverWhatsoverWhatsover5/21/2021 10:00:00 AM5/21/2021 10:00:00 AMOrangevrqm is really good
WhatsoverWhatsoverWhatsoverWhatsoverOrange is really goodwfm0
WhatsoverWhatsoverWhatsoverWhatsoverOrangeVMGT0 are everywhere
BlueberryVMGT0 is really good.Blueberry is delicous
Blueberry is reallyVMGT0 good.Blueberry is delicous3
140555WhatsoverWhatsoverWhatsoverWhatsoverWhatsover5/20/2021 1:00:00 PM5/20/2021 3:00:00 PMDraftWhatsoverOrange is reallywfm0 good3-Moderate/Limited
Orangeiwfm0 has good result
140888WhatsoverWhatsoverWhatsoverWhatsoverWhatsover5/20/2021 1:00:00 PM5/20/2021 3:00:00 PMDraftWhatsoverOrangeiwfm0 is really good3-Moderate/Limited
WhatsoverWhatsoverWhatsoverWhatsover5/20/2021 1:00:00 PM5/20/2021 3:00:00 PM
May 20, 2021 8:35 AM


Can someone help please?
 
Upvote 0
Are the expected results accurate?

If so, I don't understand how they are decided. For example, for UUID 140542, in your expected results you have these two results. I cannot see where they come from in your original data.
Orange is really goodwfm0
BlueberryVMGT0 is really good.Blueberry is delicous


Should the expected results replace the original data or should they appear elsewhere in the worksheet or in another worksheet?
 
Upvote 0
Are the expected results accurate?

If so, I don't understand how they are decided. For example, for UUID 140542, in your expected results you have these two results. I cannot see where they come from in your original data.
Orange is really goodwfm0
BlueberryVMGT0 is really good.Blueberry is delicous


Should the expected results replace the original data or should they appear elsewhere in the worksheet or in another worksheet?
Hi Peter,
I would like to take the opportunity to thank you as you are right, i forgot to add them in the main report as they show in the expected results, that was my fault, apologies to that...
So here it is again, main report:
Mr.Excel.xlsx
ABCDEFGHIJKL
1
2UUIDWhatsover1Whatsover2Whatsover3Whatsover4Whatsover5Whatsover6Whatsover7Whatsover8Whatsover9Adjust and filterWhatsover10
3140542WhatsoverWhatsoverWhatsoverWhatsoverWhatsover5/20/2021 10:00:00 AM5/20/2021 7:00:00 PMScheduledWhatsover3-Moderate/Limited
4WhatsoverWhatsoverWhatsoverWhatsover5/21/2021 10:00:00 AM5/21/2021 10:00:00 AMOrangevrqm is great for taste
5WhatsoverWhatsoverWhatsoverWhatsoverOrangevrqm is really good
6WhatsoverWhatsoverWhatsoverWhatsoverOrange is really goodwfm0
7Orange has good result
8Orange is really good
9OrangeVMGT0 are everywhere
10BlueberryVMGT0 is really good.Blueberry is delicous
11Orange is in my house
12Blueberry is really good
13Blueberry is really good.Blueberry is delicous
14BlueberryVMGT0 is really good.Blueberry is delicous1
15Blueberry is really good.Blueberry is delicous2
16Blueberry is reallyVMGT0 good.Blueberry is delicous3
17Blueberry is really good.Blueberry is delicous4
18Blueberry is really good.Blueberry is delicous5
19140555Whatsover5/20/2021 1:00:00 PM5/20/2021 3:00:00 PMDraftWhatsoverOrange is really good3-Moderate/Limited
20Orange is reallywfm0 good
21Orangeiwfm0 has good result
22Orange are everywhere
23140888Whatsover5/20/2021 1:00:00 PM5/20/2021 3:00:00 PMDraftWhatsoverOrangeiwfm0 is really good3-Moderate/Limited
24Orange has good result
25Orangeiwfm0 is really good
26May 20, 2021 8:35 AM
Sheet1


Expected output:
UUIDWhatsover1Whatsover2Whatsover3Whatsover4Whatsover5Whatsover6Whatsover7Whatsover8Whatsover9Adjust and filterWhatsover10
140542WhatsoverWhatsoverWhatsoverWhatsoverWhatsover5/20/2021 10:00:00 AM5/20/2021 10:00:00 AMScheduledWhatsoverOrangevrqm is great for taste3-Moderate/Limited
WhatsoverWhatsoverWhatsoverWhatsover5/21/2021 10:00:00 AM5/21/2021 10:00:00 AMOrangevrqm is really good
WhatsoverWhatsoverWhatsoverWhatsoverOrange is really goodwfm0
WhatsoverWhatsoverWhatsoverWhatsoverOrangeVMGT0 are everywhere
BlueberryVMGT0 is really good.Blueberry is delicous
Blueberry is reallyVMGT0 good.Blueberry is delicous3
140555WhatsoverWhatsoverWhatsoverWhatsoverWhatsover5/20/2021 1:00:00 PM5/20/2021 3:00:00 PMDraftWhatsoverOrange is reallywfm0 good3-Moderate/Limited
Orangeiwfm0 has good result
140888WhatsoverWhatsoverWhatsoverWhatsoverWhatsover5/20/2021 1:00:00 PM5/20/2021 3:00:00 PMDraftWhatsoverOrangeiwfm0 is really good3-Moderate/Limited
WhatsoverWhatsoverWhatsoverWhatsover5/20/2021 1:00:00 PM5/20/2021 3:00:00 PM
May 20, 2021 8:35 AM


"Should the expected results replace the original data or should they appear elsewhere in the worksheet or in another worksheet?" => No, nothing has to be replaced, the main focus remains on cleaning Column K respecting each UUID first as mentioned in the main description:
1- Clear Duplicates in the column
2- Clear all cells where "vrqm" or "VMGT0" or "wfm0" is not found in any word inside the cell // (note i have more but i will add them myself)
3- Shift cell up to avoid empty cells
4- Shift cell up in case the cell that matches the UUID is empty
5- Delete Empty Rows

That means each color to be cleaned seperately from other colors:
Mr.Excel.xlsx
K
1
2Adjust and filter
3
4Orangevrqm is great for taste
5Orangevrqm is really good
6Orange is really goodwfm0
7Orange has good result
8Orange is really good
9OrangeVMGT0 are everywhere
10BlueberryVMGT0 is really good.Blueberry is delicous
11Orange is in my house
12Blueberry is really good
13Blueberry is really good.Blueberry is delicous
14BlueberryVMGT0 is really good.Blueberry is delicous1
15Blueberry is really good.Blueberry is delicous2
16Blueberry is reallyVMGT0 good.Blueberry is delicous3
17Blueberry is really good.Blueberry is delicous4
18Blueberry is really good.Blueberry is delicous5
19Orange is really good
20Orange is reallywfm0 good
21Orangeiwfm0 has good result
22Orange are everywhere
23Orangeiwfm0 is really good
24Orange has good result
25Orangeiwfm0 is really good
26
Sheet1


Once that is done we will have to work on the entire table to properly format it, we will mainly need to merge empty cells in each column till they reach the line before the next UUID starts.
Finally, last task will be to merge and center the last row.

Appreciate your help on it, please note the code should detect all UUIDs as in this sample i only placed 3 UUIDs but usually they are more.
Looking forward to hearing back from you, hope all is clear now.
Thanks!
 
Upvote 0
=> No, nothing has to be replaced, the main focus remains on cleaning Column K
I think that you mis-understood what I was asking. Your original data in post #9 is shown in the range A2:L26.
Your expected results do not show rows or columns. Are they in A2:L13 (approx) in the same worksheet or in, say Y2:AJ13 (approx) in the same worksheet or even on a different worksheet?"
 
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,184
Members
452,615
Latest member
bogeys2birdies

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