Looking for advice / recommendations

ipbr21054

Well-known Member
Hi,
This below now works but can you help put the yyyy on the same line code as mmmm please.

Code:
Private Sub Worksheet_Activate()

With Sheets("GRASS INCOME")
      .Range("C3") = UCase(Format(Now, "mmmm"))
    With .Range("C3")
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlCenter
        With .Font
            .Name = "Calibri"
            .FontStyle = "Bold"
            .Size = 28
        End With
        .Borders(xlEdgeTop).LineStyle = xlContinuous
        .Borders(xlEdgeLeft).LineStyle = xlContinuous
        .Borders(xlEdgeRight).LineStyle = xlContinuous
        .Borders(xlEdgeBottom).LineStyle = xlContinuous
        .Borders(xlInsideVertical).LineStyle = xlContinuous
        .Borders(xlInsideHorizontal).LineStyle = xlContinuous
        With .Interior
            .Pattern = xlSolid
            .PatternColorIndex = xlAutomatic
            .ThemeColor = xlThemeColorAccent1
            .TintAndShade = 0.799981688894314
            .PatternTintAndShade = 0
        End With
        Range("A5").Select
        End With
        End With
End Sub
 

Jaafar Tribak

Well-known Member
Are you using a non-english edition of excel ?

As for worrying about loosing the formatting, I don't think you should because you are only clearing the contents of the cells ie : ClearContents.
 

ipbr21054

Well-known Member
Nearly but not quite.

If i use this
Code:
.Range("C3") = UCase(Format(Now, "mmmm"))
I see JULY

If i use the code you advise i see
Jul-19

Im trying to get it to be JULY 2019
 

ipbr21054

Well-known Member
Hi,
I have a workaround which takes car of it,see below,

Code:
Private Sub Worksheet_Activate()

With Sheets("GRASS INCOME")
        .Range("A3") = UCase(Format(Now, "mmmm"))
        .Range("D3") = Year(Now)
    With .Range("C3")
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlCenter
        With .Font
            .Name = "Calibri"
            .FontStyle = "Bold"
            .Size = 28
        End With
        .Borders(xlEdgeTop).LineStyle = xlContinuous
        .Borders(xlEdgeLeft).LineStyle = xlContinuous
        .Borders(xlEdgeRight).LineStyle = xlContinuous
        .Borders(xlEdgeBottom).LineStyle = xlContinuous
        .Borders(xlInsideVertical).LineStyle = xlContinuous
        .Borders(xlInsideHorizontal).LineStyle = xlContinuous
        With .Interior
        .Pattern = xlSolid
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .ThemeColor = xlThemeColorDark1
        .TintAndShade = -0.149998474074526
        .PatternTintAndShade = 0
        End With
        Range("A5").Select
        End With
        End With
End Sub


BUT
Can you advise the edit so the date & year are part of the saved pdf, see below.
[CODE]Private Sub GrassSummarySheet_Click()
    Dim strFileName As String
    
    strFileName = "C:\Users\Ian\Desktop\GRASS CUTTING\\" & Range("C3").Value & ".pdf"
    If Dir(strFileName) <> vbNullString Then
        MsgBox "SUMMARY SHEET " & Range("C3").Value & " WAS NOT SAVED AS IT ALLREADY EXISTS", vbCritical + vbOKOnly
        Exit Sub
    End If
    
    With ActiveSheet
        .ExportAsFixedFormat Type:=xlTypePDF, Filename:=strFileName, Quality:=xlQualityStandard, IncludeDocProperties:=True
        MsgBox "SUMMARY SHEET " & Range("C3").Value & " WAS SAVED SUCCESSFULLY", vbInformation + vbOKOnly
        Range("A5:B41").ClearContents
        Range("A5").Select
        ActiveWorkbook.Save
    End With
End Sub
Currently C3 BUT need to edit it correctly so its A3 D3 then i think it will work
[/CODE]
 

Jaafar Tribak

Well-known Member
Nearly but not quite.

If i use this
Code:
.Range("C3") = UCase(Format(Now, "mmmm"))
I see JULY

If i use the code you advise i see
Jul-19

Im trying to get it to be JULY 2019
That is strange... It works for me as expected.

Try this and see how it goes:
Code:
.Range("C3") = UCase(Format(Now, "mmmm")) & " " & UCase(Format(Now, "yyyy"))
 

ipbr21054

Well-known Member
Hi,
Its the same.
I will leave it and follow on with my work around if you could read the follow up post

Thanks
 

ipbr21054

Well-known Member
Hi,
No im not.

I have had to move on now as it was holding me up.

Post 15 works fine apart from the button code that it used to save the excel range as a pdf file.

Originally the cell to take the name for the pdf file was C3 but as i was haiving an issue i decided to do this.
I used cell A3 for the date of which cell A3 now shows JULY which is perfect

I used cell D3 for the year of which cell D3 now shows 2019 which is perfect

So in order to save the pdf file the new code needs to take the month from cell A3 & the year from cell D3 then save.
So the pdf file will be JULY 2019

This is the olf save code from when it was in cell C£
I now need to edit it,of which i cant so it takes into account the 2 cells for month & year being A3 & D3

Code:
Private Sub GrassSummarySheet_Click()    Dim strFileName As String
    
    strFileName = "C:\Users\Ian\Desktop\GRASS CUTTING\CURRENT GRASS SHEETS\" & Range("A3,D3").Value & ".pdf"
    If Dir(strFileName) <> vbNullString Then
        MsgBox "GRASS SHEET " & Range("A3,D3").Value & " WAS NOT SAVED AS IT ALLREADY EXISTS", vbCritical + vbOKOnly, "SUMMARY GRASS SHEET MESSAGE"
        Exit Sub
    End If
    
    With ActiveSheet
        .ExportAsFixedFormat Type:=xlTypePDF, Filename:=strFileName, Quality:=xlQualityStandard, IncludeDocProperties:=True
        MsgBox "GRASS SHEET " & Range("A3,D3").Value & " WAS SAVED SUCCESSFULLY", vbInformation + vbOKOnly, "SUMMARY GRASS SHEET MESSAGE"
        Range("A5:B41").ClearContents
        Range("A5").Select
        ActiveWorkbook.Save
    End With
End Sub
 

Jaafar Tribak

Well-known Member
Try this (Changes in red)
Code:
Private Sub GrassSummarySheet_Click()
    Dim strFileName As String
    
    strFileName = "C:\Users\Ian\Desktop\GRASS CUTTING\CURRENT GRASS SHEETS\" & [COLOR=#ff0000]Range("A3") & " " & Range("D3")[/COLOR] & ".pdf"
    If Dir(strFileName) <> vbNullString Then
        MsgBox "GRASS SHEET " & [COLOR=#ff0000]Range("A3") & " " & Range("D3")[/COLOR] & " WAS NOT SAVED AS IT ALLREADY EXISTS", vbCritical + vbOKOnly, "SUMMARY GRASS SHEET MESSAGE"
        Exit Sub
    End If
    
    With ActiveSheet
        .ExportAsFixedFormat Type:=xlTypePDF, Filename:=strFileName, Quality:=xlQualityStandard, IncludeDocProperties:=True
        MsgBox "GRASS SHEET " & [COLOR=#ff0000]Range("A3") & " " & Range("D3")[/COLOR] & " WAS SAVED SUCCESSFULLY", vbInformation + vbOKOnly, "SUMMARY GRASS SHEET MESSAGE"
        Range("A5:B41").ClearContents
        Range("A5").Select
        ActiveWorkbook.Save
    End With
End Sub
 

Some videos you may like

This Week's Hot Topics

  • Get External Data (long shot question!)
    This is likely a long shot but I am wondering if it is at all possible for Excel to somehow 'change' the contents of a URL that is being linked to...
  • Importing multiple excel files into one spreadsheet
    Hi, I'm trying to import multiple excel files (with the same format into a single spreadsheet) so that each day's file is listed underneath the...
  • Cell Formatting
    Good Morning, I need to format a few different cells in the following manners: A1 has to always add a colon (:) after whatever is typed in by a...
  • How to copy multiple rows using If
    Hi all, I'm very new to VBA and have written this simple code to copy certain cells if a certain cell within that row contains any data. I need...
  • Workbook_Change stopped working !
    I am working on an app to speed up & automate processing of Credit Cards statements. After data is input from a CSV file, it is presented to the...
  • VBA If statement
    Dear All, I have two dates, where I'd like a message box to pop, if the dates are between this criteria. [CODE] sDate1 = #10/1/2019#...
Top