Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 470
Default Insert Date in correct cell

I have a sheet (PAS) that has a type of calender to track the number of hours
I work at part-time job. Here is the set up of calender:

B125:B176 = date for beginning of week (which is a Monday) (52 rows ie weeks)
C125:G176 = columns for Mon Tue Wed Thur Fri for 52 weeks
where
B125 C125............G125
12/17/07 Mon Tue.......Fri

I would like a userform that accepts the following:
Date worked
Clock In
Clock Out

I would like to know is how to take the date worked and find the spot it is
suppsed to place total hours in. Example: If I worked on 12/27/07, the
macro needs to figure out the week it falls in and then figure out where to
place it (ie Thursday).
In this example, total hours needs to go in F126.

B125 = 12/17/07
B126 = 12/24/07 C126=Mon D126=Tue .....F126=Thur G126=Fri
B127 = 12/31/07


Thanks,
Les
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 67
Default Insert Date in correct cell

Hi,

You can try datepart function

WLMPilot wrote:
I have a sheet (PAS) that has a type of calender to track the number of hours
I work at part-time job. Here is the set up of calender:

B125:B176 = date for beginning of week (which is a Monday) (52 rows ie weeks)
C125:G176 = columns for Mon Tue Wed Thur Fri for 52 weeks
where
B125 C125............G125
12/17/07 Mon Tue.......Fri

I would like a userform that accepts the following:
Date worked
Clock In
Clock Out

I would like to know is how to take the date worked and find the spot it is
suppsed to place total hours in. Example: If I worked on 12/27/07, the
macro needs to figure out the week it falls in and then figure out where to
place it (ie Thursday).
In this example, total hours needs to go in F126.

B125 = 12/17/07
B126 = 12/24/07 C126=Mon D126=Tue .....F126=Thur G126=Fri
B127 = 12/31/07


Thanks,
Les

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 470
Default Insert Date in correct cell

I don't believe that is exactly what I am looking for. When I enter a date
via userform, I need the code to scan B125:B176 (cells that contain the date
for the beginning of the workweek ie Mondays). During the "scan", the code
will determine the appropriate row and column. Example: Date entered (I'll
name variable as datework) is 12/17/07. After pressing ENTER, code
determines that datework B126 and datework < B127. Now I will simply
substract (datework - B126) to determine the column, which would be 3. The
columns for Mon - Fri are C-G.
Therefore, the OFFSET from B126 would be (datework-B126)+1.

The equivalent Excel Function for what I am looking for is
MATCH(datework,B125:B176,1)

Les

"Equiangular" wrote:

Hi,

You can try datepart function

WLMPilot wrote:
I have a sheet (PAS) that has a type of calender to track the number of hours
I work at part-time job. Here is the set up of calender:

B125:B176 = date for beginning of week (which is a Monday) (52 rows ie weeks)
C125:G176 = columns for Mon Tue Wed Thur Fri for 52 weeks
where
B125 C125............G125
12/17/07 Mon Tue.......Fri

I would like a userform that accepts the following:
Date worked
Clock In
Clock Out

I would like to know is how to take the date worked and find the spot it is
suppsed to place total hours in. Example: If I worked on 12/27/07, the
macro needs to figure out the week it falls in and then figure out where to
place it (ie Thursday).
In this example, total hours needs to go in F126.

B125 = 12/17/07
B126 = 12/24/07 C126=Mon D126=Tue .....F126=Thur G126=Fri
B127 = 12/31/07


Thanks,
Les


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Insert Date in correct cell

here is a macro that works

Sub GetHours()
MyDate = DateValue("3/5/08")
RowCount = 125
Do While RowCount <= 176

If MyDate < Range("B" & (RowCount + 1)) Then
Exit Do
End If

RowCount = RowCount + 1
Loop
Coloffset = Weekday(MyDate, vbMonday)
hours = Range("B" & (RowCount)).Offset(0, Coloffset)
End Sub


"Equiangular" wrote:

Hi,

You can try datepart function

WLMPilot wrote:
I have a sheet (PAS) that has a type of calender to track the number of hours
I work at part-time job. Here is the set up of calender:

B125:B176 = date for beginning of week (which is a Monday) (52 rows ie weeks)
C125:G176 = columns for Mon Tue Wed Thur Fri for 52 weeks
where
B125 C125............G125
12/17/07 Mon Tue.......Fri

I would like a userform that accepts the following:
Date worked
Clock In
Clock Out

I would like to know is how to take the date worked and find the spot it is
suppsed to place total hours in. Example: If I worked on 12/27/07, the
macro needs to figure out the week it falls in and then figure out where to
place it (ie Thursday).
In this example, total hours needs to go in F126.

B125 = 12/17/07
B126 = 12/24/07 C126=Mon D126=Tue .....F126=Thur G126=Fri
B127 = 12/31/07


Thanks,
Les


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,092
Default Insert Date in correct cell

A userform with 3 textboxes and a CommandButton:
In the UserForm code module:
Option Explicit

Private Sub CommandButton1_Click()

If IsDate(Me.TextBox1.Text) Then
MyDate = CDate(Me.TextBox1.Text)
Else
MsgBox "Enter a valid date"
Me.TextBox1.Text = ""
End If
WkDay = WorksheetFunction.Weekday(MyDate)
If WkDay = 1 Or WkDay = 7 Then
MsgBox ("Cannot be a Saturday or Sunday")
Me.TextBox1.Text = ""
End If
If IsDate(Me.TextBox2.Text) Then
CkIn = CDate(Me.TextBox2.Text)
Else
MsgBox "Enter a valid time"
Me.TextBox2.Text = ""
End If

If IsDate(Me.TextBox3.Text) Then
CkOut = CDate(Me.TextBox3.Text)
Else
MsgBox "Enter a valid time"
Me.TextBox3.Text = ""
End If
UserForm1.Hide
CalcEnterHours
End Sub

In a standard code module:

Option Explicit
Public MyDate As Date
Public CkIn As Date, CkOut As Date
Public MyHours As Integer, WkDay As Integer

Sub CalcEnterHours()
Dim c As Range

If WkDay = 1 Or WkDay = 7 Then GoTo reset
MyDate = (MyDate - WkDay) + 2
Set c = Cells.Find(MyDate)
MyHours = Hour(CkOut) - Hour(CkIn)
c.Offset(0, WkDay - 1).Value = MyHours
Unload UserForm1
Exit Sub
reset:
UserForm1.Show
End Sub

PS. If you have an email address I can send it to you.
Mike F
"WLMPilot" wrote in message
...
I have a sheet (PAS) that has a type of calender to track the number of
hours
I work at part-time job. Here is the set up of calender:

B125:B176 = date for beginning of week (which is a Monday) (52 rows ie
weeks)
C125:G176 = columns for Mon Tue Wed Thur Fri for 52 weeks
where
B125 C125............G125
12/17/07 Mon Tue.......Fri

I would like a userform that accepts the following:
Date worked
Clock In
Clock Out

I would like to know is how to take the date worked and find the spot it
is
suppsed to place total hours in. Example: If I worked on 12/27/07, the
macro needs to figure out the week it falls in and then figure out where
to
place it (ie Thursday).
In this example, total hours needs to go in F126.

B125 = 12/17/07
B126 = 12/24/07 C126=Mon D126=Tue .....F126=Thur G126=Fri
B127 = 12/31/07


Thanks,
Les



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Date(Year,Month,Day) not returnign correct date jlclyde Excel Discussion (Misc queries) 8 October 16th 09 02:42 PM
Macro to insert at correct point WLMPilot Excel Programming 0 December 29th 07 01:22 AM
date not correct in cell [email protected] Setting up and Configuration of Excel 2 November 1st 06 03:09 PM
formatting a cell to display the correct date. Lee Excel Discussion (Misc queries) 1 February 23rd 06 04:04 PM
How do I insert pictures in excel with the correct aspect ratio? dfb&mkp Excel Discussion (Misc queries) 0 February 12th 06 06:09 AM


All times are GMT +1. The time now is 06:55 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"