Looking for advice / recommendations

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
2,816
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
Joined
Dec 5, 2002
Messages
7,491
Office Version
2016
Platform
Windows
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
Joined
Nov 16, 2010
Messages
2,816
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
Joined
Nov 16, 2010
Messages
2,816
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
Joined
Dec 5, 2002
Messages
7,491
Office Version
2016
Platform
Windows
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
Joined
Nov 16, 2010
Messages
2,816
Hi,
Its the same.
I will leave it and follow on with my work around if you could read the follow up post

Thanks
 

Jaafar Tribak

Well-known Member
Joined
Dec 5, 2002
Messages
7,491
Office Version
2016
Platform
Windows
Hi,
Its the same.
I will leave it and follow on with my work around if you could read the follow up post

Thanks
Are you applying some custom number format to cell C3 ?

You post15 looks fine to me it just places the year in cell D3.
 

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
2,816
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
Joined
Dec 5, 2002
Messages
7,491
Office Version
2016
Platform
Windows
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
 

Forum statistics

Threads
1,081,543
Messages
5,359,431
Members
400,527
Latest member
pro2go

Some videos you may like

This Week's Hot Topics

  • VBA (Userform)
    Hi All, I just would like to know why my code isn't working. Here is my VBA code: [CODE=vba]Private Sub OKButton_Click() Dim i As Integer...
  • List box that changes fill color
    Hello, I have gone through so many pages trying to figure this out. I have a 2020 calendar that depending on the day needs to have a certain...
  • Remove duplicates and retain one. Cross-linked cases
    Hi all I ran out of google keywords to use and still couldn't find a reference how to achieve the results of a single count. It would be great if...
  • VBA Copy and Paste With Duplicates
    Hello All, I'm in need of some input. My VBA skills are sub-par at best. I've assembled this code from basic research and it works but is...
  • Macro
    is it possible for a macro to run if the active cell value is different to the value above it
  • IF DATE and TIME
    I currently use this to check if date has passed but i also need to set a time on it too. Is it possible? [CODE=vba]=IF(B:B>TODAY(),"Not...
Top