Results 1 to 8 of 8
  1. #1
    Bronze Lounger
    Join Date
    Sep 2007
    Posts
    1,203
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I asked recently about "select" in vba. I often record bits of code instead of writing it, and manipulate afterwards. A simple border requirement generates a lot of rubbish that I have already thinned out here, but is there a simpler way of achieving this?

    Code:
    Range("P6:X16").Select
    
    	With Selection.Borders(xlEdgeLeft)
    		.Weight = xlMedium
    	End With
    	Exit Sub
    	With Selection.Borders(xlEdgeTop)
    		.Weight = xlMedium
    	End With
    	With Selection.Borders(xlEdgeBottom)
    		.Weight = xlMedium
    	End With
    	With Selection.Borders(xlEdgeRight)
    		.Weight = xlMedium
    	End With
    	
    Range("U15:W15").Select
    	
    	With Selection.Borders(xlEdgeTop)
    		.Weight = xlThin
    	End With
    	With Selection.Borders(xlEdgeBottom)
    		.Weight = xlMedium
    	End With

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    You could use

    Range("P16:X16").BorderAround LineStyle:=xlContinuous, Weight:=xlMedium
    Range("U15:W15").BorderAround LineStyle:=xlContinuous, Weight:=xlMedium

  3. #3
    Bronze Lounger
    Join Date
    Sep 2007
    Posts
    1,203
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I thinned the code even further in the edit, but would not have got to that! Thanks.

    Range("U15:W15").BorderAround LineStyle:=xlContinuous, Weight:=xlMedium

    How do I get this to just top and bottom? I notice that there is BorderAround and Borders

    Range("P6:X16").Borders(xlEdgeTop).Weight (xlThin), but I get invalid use of property when I add weight?

  4. #4
    Bronze Lounger
    Join Date
    Sep 2007
    Posts
    1,203
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ok, I have managed to do the top and bottom separately, I am assuming they cannot be done together.

    Range("U15:W15").Borders(xlEdgeTop).Weight = xlThin
    Range("U15:W15").Borders(xlEdgeBottom).LineStyle = xlDouble

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    That's correct, if you want top and border bottoms (but not borders all around an area), you'll have to do those separately.

  6. #6
    Bronze Lounger
    Join Date
    Sep 2007
    Posts
    1,203
    Thanks
    0
    Thanked 0 Times in 0 Posts
    For the life of me, I can't get this right.....

    Range("A1:M2").BordersAround LineStyle:=xlContinuous, Weight:=xlMedium
    Range("A1:M2").Borders(xlInsideHorizontal).LineSty le = xlContinuous.Weight = xlMedium
    Range("A1:M2").Borders(xlInsideVertical) LineStyle:=xlContinuous, Weight:=xlMedium

    Please, what is the correct syntax for the inside H&V lines?

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    Change

    Range("A1:M2").Borders(xlInsideHorizontal).LineSty le = xlContinuous.Weight = xlMedium

    to

    Code:
    With Range("A1:M2").Borders(xlInsideHorizontal)
      .LineStyle = xlContinuous
      .Weight = xlMedium
    End With

  8. #8
    Bronze Lounger
    Join Date
    Sep 2007
    Posts
    1,203
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    Range("A1:M2").BorderAround LineStyle:=xlContinuous, Weight:=xlMedium
    
    	With Range("A1:M2").Borders(xlInsideHorizontal)
    		.LineStyle = xlContinuous
    		.Weight = xlMedium
    	End With
    	
    	With Range("A1:M2").Borders(xlInsideVertical)
    		.LineStyle = xlContinuous
    		.Weight = xlMedium
    	End With
    Ah, I was trying for "one liners"

    Thanks

Posting Permissions

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