+ Reply to Thread
Results 1 to 5 of 5

borders cells vba do until

Hybrid View

  1. #1
    Registered User
    Join Date
    05-15-2014
    MS-Off Ver
    Excel 2003
    Posts
    25

    borders cells vba do until

    I have to apply the EXTERNAL border to the cells.
    the editor output error


    
    Dim X As Long, Y As Long
    
    X = Cells(Rows.Count, 1).End(xlUp).ROW
    
    Range("E:F").Select
    ' AT THE FOLLOWING LINE THE EDITOR FINDS ERROR
    Do Until activesheet.cell ""
    Selection.Borders(xlDiagonalDown).LineStyle = xlNone
    Selection.Borders(xlDiagonalUp).LineStyle = xlNone
    With Selection.Borders(xlEdgeLeft)
    .LineStyle = xlContinuous
    .Weight = xlThin
    .ColorIndex = xlAutomatic
    End With
    With Selection.Borders(xlEdgeTop)
    .LineStyle = xlContinuous
    .Weight = xlThin
    .ColorIndex = xlAutomatic
    End With
    With Selection.Borders(xlEdgeBottom)
    .LineStyle = xlContinuous
    .Weight = xlThin
    .ColorIndex = xlAutomatic
    End With
    With Selection.Borders(xlEdgeRight)
    .LineStyle = xlContinuous
    .Weight = xlThin
    .ColorIndex = xlAutomatic
    End With
    With Selection.Borders(xlInsideVertical)
    '.LineStyle = xlContinuous
    .Weight = xlThin
    '.ColorIndex = xlAutomatic
    End With
    With Selection.Borders(xlInsideHorizontal)
    '.LineStyle = xlContinuous
    .Weight = xlThin
    '.ColorIndex = xlAutomatic
    End With
    Loop
    End Sub
    HOW CAN I FIX THIS CODE TO SOLVE THE MISTAKE?
    THANK YOU!

  2. #2
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: borders cells vba do until

    Its all wrong :o)

    X = Cells(Rows.Count, 1).End(xlUp).ROW
    
    For each cell in Range("E" & x & ":F" & x).cells
      if cell.value<>"" then
       YOUR FORMATTING ONLY CODE
      end if
    next

    Your error was DO UNTIL x=y
    Hope this helps

    Sometimes its best to start at the beginning and learn VBA & Excel.

    Please dont ask me to do your work for you, I learnt from Reading books, Recording, F1 and Google and like having all of this knowledge in my head for the next time i wish to do it, or wish to tweak it.
    Available for remote consultancy work PM me

  3. #3
    Registered User
    Join Date
    05-15-2014
    MS-Off Ver
    Excel 2003
    Posts
    25

    Re: borders cells vba do until

    I should insert the top-border at the first row and end the bottom border at last row where there are values, how can i set up this ?

  4. #4
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: borders cells vba do until

    X = range("e1").End(xlUp).ROW

    Range("E" & x & ":F" & x).select
    selection....... all your formatting code


    You need to be clearer in your post, you had a loop, so it looked like you were looping and applying external border to each

  5. #5
    Registered User
    Join Date
    05-15-2014
    MS-Off Ver
    Excel 2003
    Posts
    25

    Re: borders cells vba do until

    ok nathansav... you were right!!! thank you!

    If it can help anyone, i fix my problem with the following code:

    lastrow = Range("e65536").End(xlUp).Row
    Range("e2:H" & lastrow).BorderAround Weight:=xlThin
    rng.Insert xlShiftDown

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Auto change borders to thick borders
    By Pierce Quality in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 11-22-2013, 11:17 PM
  2. [SOLVED] Using VBA to put borders around cells
    By nav505 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-28-2013, 10:51 AM
  3. Borders Around Cells
    By kapeller in forum Excel General
    Replies: 9
    Last Post: 06-12-2011, 08:09 AM
  4. Borders around cells...
    By syuhas in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-28-2006, 01:20 PM
  5. Borders Don't Line up with Cells.
    By Michael Hesse in forum Excel General
    Replies: 0
    Last Post: 08-30-2005, 12:05 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1