PDA

View Full Version : How to format cells in one row



mkk
08-21-2008, 08:34 AM
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

lucas
08-23-2008, 05:41 AM
Moved to the Excel help forum. You will get more excel specific help here.

mdmackillop
08-23-2008, 06:05 AM
If your data is "solid"

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