Analyzing A Range Of Cells, Clear Values Immediately Preceeding and Proceeding A Blank Cell

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,564
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I am struggling to find a vba solution for a task I need to do with a range of cells in my worksheet. Part of the problem will be trying to explain.

Consider this sample of data that prior code produces.
wsop 22.0327.xlsm
HIJKLMNOPQ
15VacnacyVacnacyVacnacyHPEHPLHPL
DISPATCH


My goal is to to eliminate any values in the cells except those immediately preceeding and proceeding an empty unshaded cell.
I think what I am aiming for is this ...
wsop 22.0327.xlsm
HIJKLMNOP
16VacnacyHPEHPLHPL
DISPATCH


The values in this range are dynamic, and can be an any combination.



 
I am still struggling to find a solution for this task. It is the one task that is causing me the greatest delay in the progress of my application. Things have changed a bit, so what was suggested doesn't work for the new structure I have.

Consider the following testing data:
BEFORE
WS 30-May-22.xlsx
HIJKLMNOPQ
13CRPRPE1RPE1RPL1
14CRPRPE1RPE1RPL1
15CRPRPE1RPE1RPL1
16CRPRPE1RPE1RPL1
17CRPRPL1RPL1RPL1
18RPL1RPL1
19RPL1RPL1
20RPL1RPL1
21CRPRPE1RPL1RPL1
22RPL1RPL1
23RPL1RPL1
24RPL1RPL1AUTOAUTO
25CRPRPL1RPL1RPL1CUL1CUL1
26RPL1RPL1
27RPL1RPL1
28RPL1RPL1RPL1CUL1
29RPL1RPL1AUTOAUTO
30RPL1RPL1AUTOAUTO
31RPL1RPL1AUTOAUTO
32NRRPL1RPL1RPL1
33NRRPL1RPL1RPL1
34NRRPL1RPL1RPL1
35NRRPL1RPL1RPL1
36CRPRPE1RPL1RPL1
37CRPRPL1RPL1RPL1
38RPL1RPL1AUTOAUTO
39RPL1CUE1RPL1
40CRPRPE1RPL1RPL1CUL1CUL1
41CRPRPE1RPL1RPL1CUL1CUL1
42RPL1RPL1AUTOAUTO
43RPL1RPL1AUTOAUTO
44RPL1RPL1AUTOAUTO
45RPL1RPL1AUTOAUTO
RPL


  • In this example ... Target cells hold crew value = RPL (all RPL1 cells will remain unshaded with the text white to obscure value or value cleared)
  • Any cell to the immediate left (except for column H) and right (except column Q) of a target cell (RPL) will have their value checked. If it is not RPL, the value in the adjacent cell remains, but the cell is shaded grey (rgb 166, 166, 166).
  • Any cell adjacent to the target cell that is shaded will remain shaded. Those cells are empty (so would not match the target cell value anyway)
  • Cells with the Value "AUTO" will remain and be shaded regardless of where they fall in relation to a target cell.

AFTER
WS 30-May-22.xlsx
HIJKLMNOPQ
13RPE1
14RPE1
15RPE1
16RPE1
17CRP
18
19
20
21RPE1
22
23
24AUTOAUTO
25CRPCUL1
26
27
28CUL1
29AUTOAUTO
30AUTOAUTO
31AUTOAUTO
32NR
33NR
34NR
35NR
36RPE1
37CRP
38AUTOAUTO
39CUE1
40RPE1CUL1CUL1
41RPE1CUL1CUL1
42AUTOAUTO
43AUTOAUTO
44AUTOAUTO
45AUTOAUTO
RPL


I will be most grateful to all that help me find a solution to this hurdle.
 
Upvote 0

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying

Forum statistics

Threads
1,221,499
Messages
6,160,164
Members
451,628
Latest member
Bale626

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