VBA Loop with multiple conditions on one sheet

LovePenguin

New Member
Joined
Nov 15, 2018
Messages
1
Not sure if this is a duplicate question but couldn't seem to find it anywhere.

I have the following sample data:
[TABLE="class: grid, width: 614"]
<tbody>[TR]
[TD][/TD]
[TD]A[/TD]
[TD]B[/TD]
[TD]C[/TD]
[TD]D[/TD]
[TD]E[/TD]
[TD]F[/TD]
[TD]G[/TD]
[TD]H[/TD]
[TD]I[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]EMPLID[/TD]
[TD]NAME[/TD]
[TD]Dept[/TD]
[TD]LOC[/TD]
[TD]JOB TITLE[/TD]
[TD]EE STS[/TD]
[TD]EFFDT[/TD]
[TD]HIST EFFDT[/TD]
[TD]HIST EE STS[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]123[/TD]
[TD]Doo, Scooby[/TD]
[TD]564[/TD]
[TD]564C[/TD]
[TD]Driver[/TD]
[TD]L[/TD]
[TD="align: right"]4/28/2018[/TD]
[TD="align: right"]3/20/2017[/TD]
[TD]L[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]123[/TD]
[TD]Doo, Scooby[/TD]
[TD]564[/TD]
[TD]564C[/TD]
[TD]Driver[/TD]
[TD]L[/TD]
[TD="align: right"]4/28/2018[/TD]
[TD="align: right"]3/15/2017[/TD]
[TD]L[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]456[/TD]
[TD]Jetson, Jane[/TD]
[TD]531[/TD]
[TD]531[/TD]
[TD]Production[/TD]
[TD]L[/TD]
[TD="align: right"]4/28/2018[/TD]
[TD="align: right"]6/2/2017[/TD]
[TD]L[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]456[/TD]
[TD]Jetson, Jane[/TD]
[TD]531[/TD]
[TD]531[/TD]
[TD]Production[/TD]
[TD]L[/TD]
[TD="align: right"]4/28/2018[/TD]
[TD="align: right"]2/20/2017[/TD]
[TD]A[/TD]
[/TR]
[TR]
[TD]6[/TD]
[TD]456[/TD]
[TD]Jetson, Jane[/TD]
[TD]531[/TD]
[TD]531[/TD]
[TD]Production[/TD]
[TD]L[/TD]
[TD="align: right"]4/28/2018[/TD]
[TD="align: right"]1/6/2017[/TD]
[TD]L[/TD]
[/TR]
[TR]
[TD]7[/TD]
[TD]456[/TD]
[TD]Jetson, Jane[/TD]
[TD]531[/TD]
[TD]531[/TD]
[TD]Production[/TD]
[TD]L[/TD]
[TD="align: right"]4/28/2018[/TD]
[TD="align: right"]2/20/2012[/TD]
[TD]A[/TD]
[/TR]
[TR]
[TD]8[/TD]
[TD]789[/TD]
[TD]Bear, Grammy[/TD]
[TD]501[/TD]
[TD]501[/TD]
[TD]Stockroom[/TD]
[TD]L[/TD]
[TD="align: right"]10/18/2018[/TD]
[TD="align: right"]10/18/2018[/TD]
[TD]L[/TD]
[/TR]
[TR]
[TD]9[/TD]
[TD]789[/TD]
[TD]Bear, Grammy[/TD]
[TD]501[/TD]
[TD]501[/TD]
[TD]Stockroom[/TD]
[TD]L[/TD]
[TD="align: right"]10/18/2018[/TD]
[TD="align: right"]4/16/2018[/TD]
[TD]A[/TD]
[/TR]
[TR]
[TD]10[/TD]
[TD]789[/TD]
[TD]Bear, Grammy[/TD]
[TD]501[/TD]
[TD]501[/TD]
[TD]Stockroom[/TD]
[TD]L[/TD]
[TD="align: right"]10/18/2018[/TD]
[TD="align: right"]3/30/2018[/TD]
[TD]L[/TD]
[/TR]
[TR]
[TD]11[/TD]
[TD]321[/TD]
[TD]Fraggle, Mokey[/TD]
[TD]501[/TD]
[TD]501[/TD]
[TD]Production[/TD]
[TD]L[/TD]
[TD="align: right"]6/2/2018[/TD]
[TD="align: right"]6/15/2007[/TD]
[TD]L[/TD]
[/TR]
[TR]
[TD]12[/TD]
[TD]321[/TD]
[TD]Fraggle, Mokey[/TD]
[TD]501[/TD]
[TD]501[/TD]
[TD]Production[/TD]
[TD]L[/TD]
[TD="align: right"]6/2/2018[/TD]
[TD="align: right"]5/21/2007[/TD]
[TD]A[/TD]
[/TR]
</tbody>[/TABLE]


What I need is a script for the following based on the sample data above:
I am trying to find the earliest date on a L row prior to an A.

So Jane Jetson is showing 2 separate L statuses. I need the earliest Hist EFFDt from the latest L status (ie: 6/2/17) to be placed in the farthest column to the right (doesn't matter which line but I need all other lines for the employee to either be blank or that date). Once it finds that it needs to move on to Grammy Bear. You will notice that Scooby Doo doesn't have any A status. Therefore I need it to recognize that 3/15/17 is the correct date I need not 3/20/17.

I think I need several DoUntil Loops in addition to some offsets. However, I am a total newbie at VBA with only basic knowledge of Macros and a few reference books. I can't seem to figure out how to put it all together.

Please help!
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.

Forum statistics

Threads
1,224,822
Messages
6,181,165
Members
453,021
Latest member
Justyna P

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