Consulting

Results 1 to 3 of 3

Thread: How to format cells in one row

  1. #1
    VBAX Newbie
    Joined
    Aug 2008
    Posts
    1
    Location

    How to format cells in one row

    Hi all,

    I am pretty new to VBA.

    I am basically trying to do some formatting in VBA.
    I cannot specify the ranges because it changes everytime.This is what I am trying to do:
    I have column headings in row 6 and it has data present from Col A to Col S. But this range changes all the time.I am trying to create border around the cols A to Cols S and inner borders also.My problem is how to specify this dynamic range.
    Below is what I am trying to do.



    I would really appreciate any help.

    Thanks

  2. #2
    VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Moved to the Excel help forum. You will get more excel specific help here.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  3. #3
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    If your data is "solid"
    [VBA]
    Sub Macro1()
    Dim rng As Range, b as long

    Set rng = Range(Cells(6, 1), Cells(6, 1).End(xlDown).End(xlToRight))

    For b = 7 To 10
    With rng.Borders(b)
    .LineStyle = xlContinuous
    .ColorIndex = xlAutomatic
    .TintAndShade = 0
    .Weight = xlThick
    End With
    Next

    For b = 11 To 12
    With rng.Borders(b)
    .LineStyle = xlContinuous
    .ColorIndex = xlAutomatic
    .TintAndShade = 0
    .Weight = xlThin
    End With
    Next
    End Sub

    [/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

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