View Single Post
  #8   Report Post  
Bob Phillips
 
Posts: n/a
Default Highlight Range - wrong macro, please edit.

Danny,

I hope I have correctly interpreted this


Sub ApplyBorders()
BordersBOLD "Applicants"
BordersBOLD "Another"
BordersBOLD "SomeOther"
'etc.
End Sub


Sub BordersBOLD(tablename As String)
Dim iLastrow As Long
Dim rng As Range

Application.Goto Reference:=tablename
ActiveCell.Offset(1, 0).Select

With ActiveCell
iLastrow = Cells(Rows.Count, .Column).End(xlUp).Row
If iLastrow <= .Row Then Exit Sub
Set rng = .Resize(iLastrow - .Row + 1, 9)
End With

With rng
.Borders(xlDiagonalDown).LineStyle = xlNone
.Borders(xlDiagonalUp).LineStyle = xlNone
With .Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With .Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With .Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With .Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With .Borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With .Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
End With
End Sub


--

HTH

RP
(remove nothere from the email address if mailing direct)


"Danny" wrote in message
...
Hi Bob,

There's one minor detail. I have several tables (several references), same
columns, different rows. The tables are separated by one blank row. I was
hoping to run the macro for each table (each table would then be enclosed
with the outline bold border). The macro below highlights all the tables

and
the outline border encloses all the tables.

'Application.Goto Reference:="Applicants"
'ActiveCell.Offset(1, 0).Select

What I plan to do is copy the above formula, change the reference (I have

11
tables/references), put in your macro so when I run it, it would make a
border outline for all the tables.

Can you please make the minor adjustments?

Thanks a lot. Have a great day!

"Bob Phillips" wrote:

Danny,

Is this what you want?

Sub BordersBOLD()
Dim iLastrow As Long
Dim rng As Range

Application.Goto Reference:="Applicants"
ActiveCell.Offset(1, 0).Select

With ActiveCell
iLastrow = Cells(Rows.Count, .Column).End(xlUp).Row
If iLastrow <= .Row Then Exit Sub
Set rng = .Resize(iLastrow - .Row + 1, 9)
End With

With rng
.Borders(xlDiagonalDown).LineStyle = xlNone
.Borders(xlDiagonalUp).LineStyle = xlNone
With .Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With .Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With .Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With .Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With .Borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With .Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
End With
End Sub



--

HTH

RP
(remove nothere from the email address if mailing direct)


"Danny" wrote in message
...
Hi,

Now I know what's wrong. below is the complete macro to make the

outline
bold.


Sub BordersBOLD()

Application.Goto Reference:="Applicants"
ActiveCell.Offset(1, 0).Select

With ActiveCell
ilastrow = Cells(Rows.Count, .Column).End(xlDown).Row
Set rng = .Resize(ilastrow - .Row + 1, 9)


Range("B13:J55").Select

Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlMedium
.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
End With
End Sub

It only works on 'Range("B13:J55").Select

I was hoping that the macro would find any named range, move down one

cell,
resize down to the last cell and 9 columns.

Please help.

"Danny" wrote:

Hi Bob,

It did it again. When you originally gave me the macro, it didn't

work.
I
re-typed it (not copying from the NG) and it worked. I did the same

thing now
and it worked again. There's something wrong with my system.

Sorry,

"Danny" wrote:

Hi Bob,

I'm glad you responded because it was you that I got the macro.

This
time, I
modifed the macro to make the outline bold. Originally, when you

gave
me the
macro, I used it for sorting.

This time, the macro won't highlight the range!

Please help me again.

Thank you.

"Bob Phillips" wrote:

Danny,

In what way does it not work. It seems fine to me, and runs on

my
system
when I add some border code.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Danny" wrote in message
...
Hi,

I got this macro from this NG and I modified it to highlight a

range.
However, it's not working. Please help.

Sub BordersBOLD()

Application.Goto Reference:="Applicants"
ActiveCell.Offset(1, 0).Select

With ActiveCell
ilastrow = Cells(Rows.Count, .Column).End(xlDown).Row
Set rng = .Resize(ilastrow - .Row + 1, 9)

'Then I will insert a macro here to make the outline borders

bold.

End With
End Sub