Consulting

Results 1 to 18 of 18

Thread: View Calendar

  1. #1

    View Calendar

    Could someone help me to create this calendar in VBA?
    Attached Files Attached Files

  2. #2
    Requesting your help,

  3. #3
    Please suggest should I ask this help under paid help section. Or please suggest something.

  4. #4

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    What needs to be done, it is already created.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  6. #6
    VBAX Regular
    Joined
    Apr 2009
    Posts
    40
    Location
    See the attachment... now

    sorry not able to upload file
    Last edited by online; 10-04-2011 at 03:59 AM. Reason: attachment was missing

  7. #7
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by online
    See the attachment... now
    What is your point?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  8. #8
    VBAX Expert shrivallabha's Avatar
    Joined
    Jan 2010
    Location
    Mumbai
    Posts
    750
    Location
    VBA has built in Calendar Control. Also there's one in KBase I think. But it comes with a caution. Here's a thread which might be of help.
    http://www.vbaexpress.com/forum/show...ht=design+time
    Regards,
    --------------------------------------------------------------------------------------------------------
    Shrivallabha
    --------------------------------------------------------------------------------------------------------
    Using Excel 2016 in Home / 2010 in Office
    --------------------------------------------------------------------------------------------------------

  9. #9
    I am still looking for VBA conversion of above attachment.

  10. #10
    VBAX Regular
    Joined
    Jan 2009
    Posts
    93
    Location

    Smile You can try this

    [VBA]
    Option Explicit

    Sub MakeCalendar_HELP_NEW()
    'By John Walkenbach
    'Distribute freely, but don't sell it
    'http://j-walk.com/ss

    Dim i As Integer

    Dim YEAR_HELP As Integer
    Dim MONTH_HELP As Integer
    Dim x

    YEAR_HELP = 2011
    MONTH_HELP = 1

    Range("a1").Activate

    For i = 1 To 12

    Select Case i
    Case 1
    ActiveCell.Offset(0, 0).Activate
    Case 2
    ActiveCell.Offset(0, 2).Activate
    Case 3
    ActiveCell.Offset(0, 2).Activate
    Case 4
    ActiveCell.Offset(10, -16).Activate
    Case 5
    ActiveCell.Offset(0, 2).Activate
    Case 6
    ActiveCell.Offset(0, 2).Activate
    Case 7
    ActiveCell.Offset(10, -16).Activate
    Case 8
    ActiveCell.Offset(0, 2).Activate
    Case 9
    ActiveCell.Offset(0, 2).Activate
    Case 10
    ActiveCell.Offset(10, -16).Activate
    Case 11
    ActiveCell.Offset(0, 2).Activate
    Case 12
    ActiveCell.Offset(0, 2).Activate
    End Select



    '''''''''''''''''''''''''''''''''''''''''''''''''''''''
    'This procedure inserts a "live" calendar at the active
    'cell. It uses eight rows and seven columns
    'If it overwrites your data, tough. No undo.
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''

    'Is the range empty?
    'If Application.CountA(Range(ActiveCell, ActiveCell.Offset(7, 6))) <> 0 Then
    ' If MsgBox("OK to overwrite existing data?", vbYesNo, "Calendar Maker") <> vbYes Then Exit Sub
    'End If

    'Insert the month/year
    'ActiveCell.Value = DateSerial(YEAR(Now), MONTH(Now), 1)
    ActiveCell.Value = DateSerial(YEAR_HELP, MONTH_HELP, 1)
    ActiveCell.NumberFormat = "mmmm, yyy"

    'Insert day headings
    With Range(ActiveCell.Offset(1, 0), ActiveCell.Offset(1, 6))
    .Formula = Array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat")
    .HorizontalAlignment = xlCenter
    .Interior.ColorIndex = 27
    .Font.Bold = True
    End With

    'Insert an array formula
    On Error GoTo NoCanDo
    With Range(ActiveCell.Offset(2, 0), ActiveCell.Offset(7, 6))
    'Formula would be too long, so insert shorter formula and replace characters.
    .FormulaArray = "=IF(MONTH(DATE(y,m,1))<>MONTH(DATE(y,m,1)-(WEEKDAY(DATE(y,m,1))-1)+{0;1;2;3;4;5}*7+{1,2,3,4,5,6,7}-1),"""",DATE(y,m,1)-(WEEKDAY(DATE(y,m,1))-1)+{0;1;2;3;4;5}*7+{1,2,3,4,5,6,7}-1)"
    .Replace What:=",m,", Replacement:=",MONTH(" & ActiveCell.Address(False, False) & "),"
    .Replace What:="y,", Replacement:="YEAR(" & ActiveCell.Address(False, False) & "),"
    .NumberFormat = "d"
    .HorizontalAlignment = xlCenter
    .Interior.ColorIndex = 36
    End With

    'Add some borders
    With Range(ActiveCell, ActiveCell.Offset(7, 6))
    .Borders(xlEdgeLeft).LineStyle = xlContinuous
    .Borders(xlEdgeTop).LineStyle = xlContinuous
    .Borders(xlEdgeBottom).LineStyle = xlContinuous
    .Borders(xlEdgeRight).LineStyle = xlContinuous
    .Borders(xlInsideVertical).LineStyle = xlContinuous
    .Borders(xlInsideHorizontal).LineStyle = xlContinuous
    End With

    ' Merge and center month/year
    Application.DisplayAlerts = False
    With Range(ActiveCell, ActiveCell.Offset(0, 6))
    .Merge
    .HorizontalAlignment = xlCenter
    .Interior.ColorIndex = 1
    .Font.ColorIndex = 2
    .Font.Bold = True
    End With
    Application.DisplayAlerts = True
    'Exit Sub

    MONTH_HELP = MONTH_HELP + 1

    Next i

    Cells.Select
    Selection.ColumnWidth = 5.43

    NoCanDo:
    ' MsgBox "There was a problem writing creating the calendar.", vbInformation
    End Sub
    [/VBA]

    happy and sunny day

  11. #11
    Thanks, it was great help.

    How can I modify above program that current month interior color to look different than remaining month.

    I just wanted that formula don't appear in excel sheet. For this purpose, can I use: -

    .cells.value = .cells.value

  12. #12
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    If you don't have formulae, it won't be dynamic, that is it won't change if you scroll the year.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  13. #13
    Hi Bob, above program was not dynamic.

  14. #14
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    The original you showed was though, and you seemed to be suggesting that was what you aspired to. Anyway, if you are happy ...
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  15. #15
    Quote Originally Posted by justdriving
    Thanks, it was great help.

    How can I modify above program that current month interior color to look different than remaining month.

    I just wanted that formula don't appear in excel sheet. For this purpose, can I use: -

    .cells.value = .cells.value

  16. #16
    VBAX Expert shrivallabha's Avatar
    Joined
    Jan 2010
    Location
    Mumbai
    Posts
    750
    Location
    If your target is to hide formula then you can always use Protect Sheet method.

    Select All Cells with formulas and then go to "Format cells" options. On the Protection Tab Check the option named "Hidden". Then protect the sheet. People using the sheet won't be able to see formulas!
    Regards,
    --------------------------------------------------------------------------------------------------------
    Shrivallabha
    --------------------------------------------------------------------------------------------------------
    Using Excel 2016 in Home / 2010 in Office
    --------------------------------------------------------------------------------------------------------

  17. #17
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    Quote Originally Posted by justdriving
    Thanks, it was great help.

    How can I modify above program that current month interior color to look different than remaining month.

    I just wanted that formula don't appear in excel sheet. For this purpose, can I use: -

    .cells.value = .cells.value
    What efforts have you made thus far?

  18. #18
    VBAX Expert
    Joined
    Aug 2004
    Posts
    810
    Location
    here, try this
    [VBA]
    Option Explicit

    Sub MakeCalendar_HELP_NEW()
    'By John Walkenbach
    'Distribute freely, but don't sell it
    'http://j-walk.com/ss

    Dim i As Integer

    Dim YEAR_HELP As Integer
    Dim MONTH_HELP As Integer
    Dim x

    YEAR_HELP = 2011
    MONTH_HELP = 1

    Range("a1").Activate

    For i = 1 To 12

    Select Case i
    Case 1
    ActiveCell.Offset(0, 0).Activate
    Case 2
    ActiveCell.Offset(0, 2).Activate
    Case 3
    ActiveCell.Offset(0, 2).Activate
    Case 4
    ActiveCell.Offset(10, -16).Activate
    Case 5
    ActiveCell.Offset(0, 2).Activate
    Case 6
    ActiveCell.Offset(0, 2).Activate
    Case 7
    ActiveCell.Offset(10, -16).Activate
    Case 8
    ActiveCell.Offset(0, 2).Activate
    Case 9
    ActiveCell.Offset(0, 2).Activate
    Case 10
    ActiveCell.Offset(10, -16).Activate
    Case 11
    ActiveCell.Offset(0, 2).Activate
    Case 12
    ActiveCell.Offset(0, 2).Activate
    End Select



    '''''''''''''''''''''''''''''''''''''''''''''''''''''''
    'This procedure inserts a "live" calendar at the active
    'cell. It uses eight rows and seven columns
    'If it overwrites your data, tough. No undo.
    '''''''''''''''''''''''''''''''''''''''''''''''''''''''

    'Is the range empty?
    'If Application.CountA(Range(ActiveCell, ActiveCell.Offset(7, 6))) <> 0 Then
    ' If MsgBox("OK to overwrite existing data?", vbYesNo, "Calendar Maker") <> vbYes Then Exit Sub
    'End If

    'Insert the month/year
    'ActiveCell.Value = DateSerial(YEAR(Now), MONTH(Now), 1)
    ActiveCell.Value = DateSerial(YEAR_HELP, MONTH_HELP, 1)
    ActiveCell.NumberFormat = "mmmm, yyy"

    'Insert day headings
    With Range(ActiveCell.Offset(1, 0), ActiveCell.Offset(1, 6))
    .Formula = Array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat")
    .HorizontalAlignment = xlCenter
    .Interior.ColorIndex = 27
    .Font.Bold = True
    End With

    'Insert an array formula
    On Error GoTo NoCanDo
    With Range(ActiveCell.Offset(2, 0), ActiveCell.Offset(7, 6))
    'Formula would be too long, so insert shorter formula and replace characters.
    .FormulaArray = "=IF(MONTH(DATE(y,m,1))<>MONTH(DATE(y,m,1)-(WEEKDAY(DATE(y,m,1))-1)+{0;1;2;3;4;5}*7+{1,2,3,4,5,6,7}-1),"""",DATE(y,m,1)-(WEEKDAY(DATE(y,m,1))-1)+{0;1;2;3;4;5}*7+{1,2,3,4,5,6,7}-1)"
    .Replace What:=",m,", Replacement:=",MONTH(" & ActiveCell.Address(False, False) & "),"
    .Replace What:="y,", Replacement:="YEAR(" & ActiveCell.Address(False, False) & "),"
    .NumberFormat = "d"
    .HorizontalAlignment = xlCenter
    If i = Month(Now) Then
    .Interior.ColorIndex = 3
    Else
    .Interior.ColorIndex = 36
    End If
    End With

    'Add some borders
    With Range(ActiveCell, ActiveCell.Offset(7, 6))
    .Borders(xlEdgeLeft).LineStyle = xlContinuous
    .Borders(xlEdgeTop).LineStyle = xlContinuous
    .Borders(xlEdgeBottom).LineStyle = xlContinuous
    .Borders(xlEdgeRight).LineStyle = xlContinuous
    .Borders(xlInsideVertical).LineStyle = xlContinuous
    .Borders(xlInsideHorizontal).LineStyle = xlContinuous
    End With

    ' Merge and center month/year
    Application.DisplayAlerts = False
    With Range(ActiveCell, ActiveCell.Offset(0, 6))
    .Merge
    .HorizontalAlignment = xlCenter
    .Interior.ColorIndex = 1
    .Font.ColorIndex = 2
    .Font.Bold = True
    End With
    Application.DisplayAlerts = True
    'Exit Sub

    MONTH_HELP = MONTH_HELP + 1

    Next i

    Cells.Select
    Selection.ColumnWidth = 5.43

    NoCanDo:
    ' MsgBox "There was a problem writing creating the calendar.", vbInformation
    End Sub
    [/VBA]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •