Results 1 to 2 of 2

Thread: Searching for interior color and borders

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2006
    Posts
    223

    Searching for interior color and borders

    I'd like to find the last row that contains any one of the following things:

    1. Text
    2. Interior color
    3. Borders


    This construct:

    Code:
    with wks
       lastRow = .Columns(col).Find("*", SearchOrder:=xlByRows, _
          LookIn:=xlValues, SearchDirection:=xlPrevious).row
    end with
    seems to only find text. I can accomplish my goal by looping over each cell in the column, something like (untested):

    Code:
    Dim i as integer
    
    with wks
       for i = 65535 to 1 step -1
          if not isEmpty(.cells(i,col)) and .cells(i,col).interior.colorIndex <> xlNone then _
             exit for
       next i
    end with
    
    msgbox("Last row with anything is " + str(i))
    I don't know how to tell if there's a border, but in principle I can Google for it, and if I can't find it, ask here, and use it as a third condition in the conditional.

    If there a faster or shorter way of doing this?

    Thanks!

  2. #2
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Searching for interior color and borders

    I don't know how to tell if there's a border
    Does this help?

    vb Code:
    1. 'Example for cell A1
    2. If Range("A1").BorderAround = True Then
    3.     MsgBox "This cell has a border"
    4. End If

    If there a faster or shorter way of doing this?
    Tip: If you loop through all the 65536 cells then excel will be damn slow. Check out "SpecialCells Method" in VBA Help to find the last cell. Then you can combine both to get the desired result...
    Last edited by Siddharth Rout; Mar 27th, 2007 at 05:23 PM.
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

Posting Permissions

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



Click Here to Expand Forum to Full Width