Can you check my code please

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
3,380
Office Version
2007
Platform
Windows
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
[COLOR=#ff0000]    With Sheets("GRASS INCOME")[/COLOR]
[COLOR=#ff0000]        .Range ("A4:E30")[/COLOR]
[COLOR=#ff0000]         Selection.Borders(xlDiagonalDown).LineStyle = xlNone[/COLOR]
[COLOR=#ff0000]         Selection.Borders(xlDiagonalUp).LineStyle = xlNone[/COLOR]
[COLOR=#ff0000]    With Selection.Borders(xlEdgeLeft)[/COLOR]
[COLOR=#ff0000]        .LineStyle = xlContinuous[/COLOR]
[COLOR=#ff0000]        .ColorIndex = 0[/COLOR]
[COLOR=#ff0000]        .TintAndShade = 0[/COLOR]
[COLOR=#ff0000]        .Weight = xlThin[/COLOR]
[COLOR=#ff0000]    End With[/COLOR]
[COLOR=#ff0000]        Range("A5").Select[/COLOR]
[COLOR=#ff0000]    End With[/COLOR]
[COLOR=#ff0000]    End With[/COLOR]
[COLOR=#ff0000]    End With[/COLOR]
[COLOR=#ff0000]    End With[/COLOR]
End Sub
Thanks very much and have a nice day
 

Some videos you may like

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.

Logit

Well-known Member
Joined
Aug 31, 2016
Messages
3,346
.
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
 

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
3,380
Office Version
2007
Platform
Windows
Hi,
That didnt add any line borders etc.
But it did resize all the columns & unmerge 4 cells
 

shg

MrExcel MVP
Joined
May 7, 2008
Messages
21,752
Office Version
2010
Platform
Windows
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
 

Watch MrExcel Video

Forum statistics

Threads
1,102,592
Messages
5,487,745
Members
407,609
Latest member
Chrissie1970

This Week's Hot Topics

  • Timer in VBA - Stop, Start, Pause and Reset
    [CODE=vba][/CODE] Option Explicit Dim CmdStop As Boolean Dim Paused As Boolean Dim Start Dim TimerValue As Date Dim pausedTime As Date Sub...
  • how to updates multiple rows in muliselect listbox
    Hello everyone. I need help with below code. code is only chaning 1st row in mulitiselect list box. i know issue with code...
  • Delete Row from Table
    I am trying to delete a row from a table using VBA using a named range to find what I need to delete. My Range is finding the right cell. In the...
  • Assigning to a variable
    I have a for each block where I want to assign the value in column 5 of the found row to the variable Serv. [CODE=vba] For Each ws In...
  • Way to verify information
    Hi All, I don't know what to call this formula, and therefore can't search. I have a spreadsheet with information I want to reference...
  • Active Cell Address – Inactive Sheet
    How to use VBA to get the cell address of the active cell in an inactive worksheet and then place that cell address in a location on the current...
Top