Can you check my code please
Results 1 to 5 of 5

Thread: Can you check my code please

  1. #1
    Board Regular
    Join Date
    Nov 2010
    Posts
    2,328
    Post Thanks / Like
    Mentioned
    6 Post(s)
    Tagged
    0 Thread(s)

    Default Can you check my code please

    Hi,
    The code is supplied below,
    All was working spot on until the code in Red was added.
    Basically i recorded a macro and took the coede from there and placed it here.
    What is hould do is the following.
    Range A4:E30 add All borders "thats it"
    But whilst you are there i would like to also add the All borderds to this range here,i didnt get around to that part as the above keep stopping me.
    Range also to be included,
    D31:E31
    C35:C37
    E35:E37

    Code:
    Private Sub Worksheet_Activate()
    
        With Sheets("GRASS INCOME")
            .Range("A3") = UCase(Format(Now, "mmmm"))
            .Range("D3") = Year(Now)
        With .Range("A1:E3")
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlCenter
        With .Font
            .ThemeColor = xlThemeColorLight1
            .TintAndShade = 0
            .Name = "Calibri"
            .FontStyle = "Bold"
            .Size = 22
        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
        With Sheets("GRASS INCOME")
            .Range ("A4:E30")
             Selection.Borders(xlDiagonalDown).LineStyle = xlNone
             Selection.Borders(xlDiagonalUp).LineStyle = xlNone
        With Selection.Borders(xlEdgeLeft)
            .LineStyle = xlContinuous
            .ColorIndex = 0
            .TintAndShade = 0
            .Weight = xlThin
        End With
            Range("A5").Select
        End With
        End With
        End With
        End With
    End Sub
    Thanks very much and have a nice day
    I have learning difficulties so please be patient if i'm slow on the uptake,Thanks Very Much...

  2. #2
    Board Regular Logit's Avatar
    Join Date
    Aug 2016
    Location
    United States
    Posts
    2,671
    Post Thanks / Like
    Mentioned
    34 Post(s)
    Tagged
    1 Thread(s)

    Default Re: Can you check my code please

    .
    I broke it down into sections :

    Code:
    Private Sub Worksheet_Activate()
    
    
        With Sheets("GRASS INCOME")
            .Range("A3") = UCase(Format(Now, "mmmm"))
            .Range("D3") = Year(Now)
        End With
        
        With Sheets("GRASS INCOME").Range("A1:E3")
            .Borders(xlEdgeTop).LineStyle = xlContinuous
            .Borders(xlEdgeLeft).LineStyle = xlContinuous
            .Borders(xlEdgeRight).LineStyle = xlContinuous
            .Borders(xlEdgeBottom).LineStyle = xlContinuous
            .Borders(xlInsideVertical).LineStyle = xlContinuous
            .Borders(xlInsideHorizontal).LineStyle = xlContinuous
        End With
        
        With Sheets("GRASS INCOME").Range("A1:E3").Interior
            .Pattern = xlSolid
            .Pattern = xlSolid
            .PatternColorIndex = xlAutomatic
            .ThemeColor = xlThemeColorDark1
            .TintAndShade = -0.149998474074526
            .PatternTintAndShade = 0
        End With
        
         With Sheets("GRASS INCOME").Range("A1:E3").Borders(xlEdgeLeft)
            .LineStyle = xlContinuous
            .ColorIndex = 0
            .TintAndShade = 0
            .Weight = xlThin
         End With
        
        With Sheets("GRASS INCOME").Range("A1:E3")
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlCenter
        End With
        
        With Sheets("GRASS INCOME").Range("A4:E30")
             Selection.Borders(xlDiagonalDown).LineStyle = xlNone
             Selection.Borders(xlDiagonalUp).LineStyle = xlNone
        End With
        
        With Sheets("GRASS INCOME").Range("A4:E30").Font '
            .ThemeColor = xlThemeColorLight1
            .TintAndShade = 0
            .Name = "Calibri"
            .FontStyle = "Bold"
            .Size = 22
        End With
        
        Range("A5").Select
        
    End Sub

  3. #3
    Board Regular
    Join Date
    Nov 2010
    Posts
    2,328
    Post Thanks / Like
    Mentioned
    6 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Can you check my code please

    Hi,
    That didnt add any line borders etc.
    But it did resize all the columns & unmerge 4 cells
    I have learning difficulties so please be patient if i'm slow on the uptake,Thanks Very Much...

  4. #4
    MrExcel MVP shg's Avatar
    Join Date
    May 2008
    Location
    The Great State of Texas
    Posts
    21,590
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    13 Thread(s)

    Default Re: Can you check my code please

    Sounds to me like all you need is ...

    Code:
    Private Sub Worksheet_Activate()
      Range("A3") = UCase(Format(Now, "mmmm"))
      Range("D3") = Year(Now)
      Range("A1:E3").HorizontalAlignment = xlCenter
      Range("A1:E3").VerticalAlignment = xlCenter
      Range("A1:E30, D31:E31, C35:C37, E35:E37").Borders.LineStyle = xlContinuous
      Range("A5").Select
    End Sub

  5. #5
    Board Regular
    Join Date
    Nov 2010
    Posts
    2,328
    Post Thanks / Like
    Mentioned
    6 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Can you check my code please

    Majic works a treat many thanks.
    Would you mind taking a quick peak at this.
    Basically 2 code.
    Code 1 saves sheet 1 BUT code 2 also saves sheet 1 for no reason that i can see.

    https://www.mrexcel.com/forum/excel-...ome-sheet.html
    I have learning difficulties so please be patient if i'm slow on the uptake,Thanks Very Much...

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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