Hide Rows based on Time Selection in timesheet.

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

thanks for looking @ this.

Is it possible too.

I have a timesheet that users use everyday. It has a column that starts @
5:00am and goes to 12:00 Midnight. Each Row respresents a Tenth of an hour.
In two other cells I have a "Arrival TIME" and " Departure TIME" .. Normally
they start @ 8:00am, leave @ 5:00pm .. Both these are DataValidation List
using the same 5:00am to 12:00am list.
Is it possible too, based on the users selection of ARRIVAL time, to HIDE
ROWS in the TIME COLUMN that are less than the ARRIVAL Time? .. if the user
comes in @ 8:00 am, it would hide rows from 5:00am to 7:50am .. I would like
to do the same with Departure Time.. If the user leaves @ 5:00pm .. it would
hide from 5:10pm to 12:00 midnight.. Basically to "shorten" the timesheet up
to the hours they are working.

I hope I have explained this correclty. Thanks for you help.

thom
 
You use a new sheet for each day?

Assume time column is column A and times start in cell A2

Dim rng as Range, res as Variant, res1 as Variant
set rng = Range(A2,cells(rows.count,1).End(xlup))

Set StartTime = Range("F9")
set EndTime = Range("F10")
res = Application.Match(StartTime,rng,0)
res1 = application.Match(EndTime,rng,0)
if not iserror(res) then
rows(2).Resize(res).Entirerow.Hidden = True
end if
if not iserror(res1) then
range(rng(res1).offset(1,0),rng(rng.count)).EntireRow.Hidden = True
End if
 
private Sub Worksheet_Change(ByVal Target As Range)
Dim iRow As Long
On Error GoTo ws_exit:
Application.EnableEvents = False
If Not Intersect(Target, Me.Range("A1:A259")) Is Nothing Then
With Target
iRow = .row
Me.Rows("1:259").Hidden = False
Me.Rows("1:" & iRow - 1).Hidden = True
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.




How do you propose toi unhide them?

--

HTH

RP
(remove nothere from the email address if mailing direct)
 
Thanks for the reply..
question?
I assume this is a "private Sub Worksheet_Change(ByVal Target As Range)" ..
How do I add this code to an already existing "private Sub Worksheet_Change"
... that is on the sheet? ...
Also, here is the actual Cell references...

Range is B15:B204
Set StartTime = Range("H4")
set EndTime = Range("H5")

Thanks...
 
Tom, I also get a
Run-time Error 1004
Method 'Range' of object'_Worksheet' failed
on line:
set rng = Range(B15,cells(rows.count,1).End(xlup))

thanks...
I was also trying to run as a Macro..
 
set rng = Range("B15",cells(rows.count,1).End(xlup))

My typo.

No, it isn't a change event, I assumed this was a onetime thing. If you
want to react whenever someone makes an entry, you might try Bob's code.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Excel Excel IF variable based on time of day 0
TIME SHEETS 1
Add Hours by Looping through Data Q 27
Timesheet formula problem 2
Date Subtraction/Time between Occurences 5
Need help with time in a row. 3
Calendar 2
Timesheet 6

Back
Top