PC Review


Reply
Thread Tools Rate Thread

Code assistance

 
 
SF
Guest
Posts: n/a
 
      2nd Jan 2008
Hi,

I need to create timesheets (12 sheets). Each sheet will have Employee Name
in the first column and a dtae range of respective month. Is there a way to:

1 - Populate days of a given month across the worksheet (say starting from
B2)
2 - Determince if the date fall under Staurday or Sunday, if this tru,
highlighted cell with Yelow color

SF


 
Reply With Quote
 
 
 
 
Joe
Guest
Posts: n/a
 
      2nd Jan 2008
Hi SF,

Try this ....
The code is given below...



Private Sub CommandButton1_Click()
' Will add a sheet and put all the dates of a month in 2nd column
' with weekends in Grey Color

Dim Y, M, D As Variant
Const CGrey As Integer = 15 ' or Assign the color code of ur choice
Dim i As Integer


M = Month(Now()) ' or Assign the number of the month (1, 2, ....,
12)
Y = Year(Now()) ' or Assign ur choice. (2007, 2008, ...)
i = 1

Sheets.Add
ActiveSheet.Name = "DD" 'Assign Ur text here

Do While Month(DateSerial(Y, M, i)) = M
With ActiveSheet
.Cells(i, 2) = DateSerial(Y, M, i)
D = Weekday(.Cells(i, 2), vbMonday)
If D = 6 Or D = 7 Then .Cells(i, 2).Interior.ColorIndex =
CGrey
End With
i = i + 1
Loop

End Sub




Check and let me know....

HTH,
Joe
 
Reply With Quote
 
Joe
Guest
Posts: n/a
 
      2nd Jan 2008
Hi SF,


Try the code below and let me know......




Private Sub CommandButton1_Click()
' Will add a sheet and put all the dates of a month in 2nd column
' with weekends in Grey Color

Dim Y, M, D, WD As Variant
Const CGrey As Integer = 15
' or Assign the color code of ur choice



M = Month(Now())
' or Assign the number of the month (1, 2, ...., 12)

Y = Year(Now())
' or Assign ur choice. (2007, 2008, ...)

D = 1

Sheets.Add
ActiveSheet.Name = "DD"
'Assign Ur text here

Do While Month(DateSerial(Y, M, D)) = M
With ActiveSheet
.Cells(D, 2) = DateSerial(Y, M, D)
WD = Weekday(.Cells(D, 2), vbMonday)
If WD = 6 Or WD = 7 Then _
.Cells(D, 2).Interior.ColorIndex = CGrey
End With
D = D + 1
Loop

End Sub




HTH
Joe
 
Reply With Quote
 
SF
Guest
Posts: n/a
 
      2nd Jan 2008
Thank you very much,

The code work very well.

SF

"Joe" <(E-Mail Removed)> wrote in message
news:4d201fc7-890c-429f-8fdf-(E-Mail Removed)...
> Hi SF,
>
>
> Try the code below and let me know......
>
>
>
>
> Private Sub CommandButton1_Click()
> ' Will add a sheet and put all the dates of a month in 2nd column
> ' with weekends in Grey Color
>
> Dim Y, M, D, WD As Variant
> Const CGrey As Integer = 15
> ' or Assign the color code of ur choice
>
>
>
> M = Month(Now())
> ' or Assign the number of the month (1, 2, ...., 12)
>
> Y = Year(Now())
> ' or Assign ur choice. (2007, 2008, ...)
>
> D = 1
>
> Sheets.Add
> ActiveSheet.Name = "DD"
> 'Assign Ur text here
>
> Do While Month(DateSerial(Y, M, D)) = M
> With ActiveSheet
> .Cells(D, 2) = DateSerial(Y, M, D)
> WD = Weekday(.Cells(D, 2), vbMonday)
> If WD = 6 Or WD = 7 Then _
> .Cells(D, 2).Interior.ColorIndex = CGrey
> End With
> D = D + 1
> Loop
>
> End Sub
>
>
>
>
> HTH
> Joe



 
Reply With Quote
 
Joe
Guest
Posts: n/a
 
      3rd Jan 2008
On Jan 2, 2:09*pm, "SF" <x...@online.com.kh> wrote:
> Thank you very much,
>
> The code work very well.
>
> SF
>
> "Joe" <Joe.Varghese.J...@gmail.com> wrote in message
>
> news:4d201fc7-890c-429f-8fdf-(E-Mail Removed)...
>
>
>
> > Hi SF,

>
> > Try the code below and let me know......

>
> > Private Sub CommandButton1_Click()
> > ' Will add a sheet and put all the dates of a month in 2nd column
> > ' with weekends in Grey Color

>
> > Dim Y, M, D, WD As Variant
> > Const CGrey As Integer = 15
> > ' or Assign the color code of ur choice

>
> > M = Month(Now())
> > ' or Assign the number of the month (1, 2, ...., 12)

>
> > Y = Year(Now())
> > ' or Assign ur choice. *(2007, 2008, ...)

>
> > D = 1

>
> > Sheets.Add
> > ActiveSheet.Name = "DD"
> > 'Assign Ur text here

>
> > Do While Month(DateSerial(Y, M, D)) = M
> > * *With ActiveSheet
> > * * * *.Cells(D, 2) = DateSerial(Y, M, D)
> > * * * *WD = Weekday(.Cells(D, 2), vbMonday)
> > * * * *If WD = 6 Or WD = 7 Then _
> > * * * * * *.Cells(D, 2).Interior.ColorIndex = CGrey
> > * *End With
> > * *D = D + 1
> > Loop

>
> > End Sub

>
> > HTH
> > Joe- Hide quoted text -

>
> - Show quoted text -


Nice...
Welcome.

Joe
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need assistance with code, please winnie123 Microsoft Excel Programming 8 1st Mar 2009 03:17 PM
Help with code assistance =?Utf-8?B?TWVraW5uaWs=?= Microsoft Excel Programming 3 5th Oct 2007 07:39 PM
Code assistance ladybug via AccessMonster.com Microsoft Access VBA Modules 11 13th Apr 2007 01:18 AM
Assistance with VBA code on MAC Jim May Microsoft Excel Programming 2 20th Oct 2006 06:57 PM
Code assistance please JMay Microsoft Excel Programming 3 4th Sep 2004 05:21 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:12 PM.