Change/move data when cell date => today()

archerks

Board Regular
Joined
Jun 5, 2002
Messages
119
I have a time off sheet that is filled by a user form. Besides listing the actual "Vacation" taken I have added "Vac Request". I would like to be to change all the "Vac Request" rows into actual "Vacation" when the "Vac Request" start date => today() when I press a Command Button.

On a ROW BY ROW basis here is the needs to be done if a value in Col R is > 0 and the date in Col C is => the Today() then move (cut) the value in Col R to Col F and change Col Q from "Vac Request" to "Vacation".

There may be up to 3000 rows that this needs to evaluate.
Time Off 2005.xls
ABCDEFGHIJKLMNOPQR
199RefNameStartDateReturnedHolidayVacSickFuneralOtherTardyDeptOther1/2DayMgrRefDaysTypeVacReq
200100Startof20051/1/20051/2/200510.110.210.310.410.510.6
201101Schuetz,John1/3/20051/4/20051.0Eng1.0Vacation
202102Menold,Donald1/7/20051/11/20052.0Service2.0Vacation
203103Hill,Chad1/5/20051/5/20051.0Shop1.0Tardy
204104Duryea,Chad1/5/20051/5/20051.0Shop1.0Tardy
205105WilliamsII,Lloyd1/5/20051/6/20051.0ShopMgr1.0Vacation
206106Hughes,Woody1/3/20051/10/20055.0ShopDisability5.0Other
207107Wilhelm,William1/7/20051/10/20050.5ShopAfternoon0.5Vacation
208108Shaw,David1/14/20051/18/2005AcctAfternoonofStartDate1.5VacRequest1.5
209109Rockey,John1/28/20052/2/2005Shop3.0VacRequest3.0
210
TimeOff
 
Appears to work in testing:

<font face=Courier New><SPAN style="color:#00007F">Sub</SPAN> UpdateVacation()
    <SPAN style="color:#00007F">Dim</SPAN> rngColB <SPAN style="color:#00007F">As</SPAN> Range, rngCell <SPAN style="color:#00007F">As</SPAN> Range
    <SPAN style="color:#00007F">Const</SPAN> bytOffsetBtoStart <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Byte</SPAN> = 1
    <SPAN style="color:#00007F">Const</SPAN> bytOffsetBToVac <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Byte</SPAN> = 4
    <SPAN style="color:#00007F">Const</SPAN> bytOffsetBToReq <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Byte</SPAN> = 16
    <SPAN style="color:#00007F">Set</SPAN> rngColB = Range("B1", [B65536].End(xlUp))
    
    <SPAN style="color:#00007F">For</SPAN> <SPAN style="color:#00007F">Each</SPAN> rngCell <SPAN style="color:#00007F">In</SPAN> rngColB
        <SPAN style="color:#00007F">If</SPAN> rngCell.Offset(, bytOffsetBtoStart) <= Date _
        And rngCell.Offset(, bytOffsetBToReq) <> 0 <SPAN style="color:#00007F">Then</SPAN>
            rngCell.Offset(, bytOffsetBToVac) = rngCell.Offset(, bytOffsetBToReq)
            rngCell.Offset(, bytOffsetBToReq).ClearContents
        <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN>
    <SPAN style="color:#00007F">Next</SPAN> rngCell
        
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN>
</FONT>

Comment: one could quite easily simply code the appropriate offsets into the calls to the .Offset() method. However, if the layout of the data ever changes, i.e. a column is added or deleted, then updating the code is harder. For future upkeep, it's easier if you define the offsets between columns as constants and reference those. That way if you insert or delete a column you simply update the constant and you're done.
HTH
 
Upvote 0
Thank you....

Just added info for my Col Q and everyting works great.

Where can I find reading info about offsets and how to use them? Offsets are new (unknown to me).

Thanks again,
Dave
 
Upvote 0
<ul>[*]In the VBE, hit F2 to call up the object browser.[*]In the left list pane click and type "R". That should jump you to the Range object (scroll to it if for some reason it doesn't).[*]In the right list pane click and type "O". That should jump you to the Offset property.[*]Just hit F1 for the help on Offset.[/list]There is also an OFFSET() worksheet function in Excel. You can just type that into help in Excel for more info.
 
Upvote 0

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