VBA cell selection and format

  • Thread starter Thread starter MTBer
  • Start date Start date
M

MTBer

I have a macro that produces a list of cell references in this format o
sheet1, in cell A1:A3 (note the range can grow or shrink)

Sheet2!C15
Sheet2!D53
Sheet2!G70


what would be the best way to now highlight the cell references an
format the background of these cells
 
One way:

Option Explicit
Sub testme01()

Dim myRng As Range
Dim myCell As Range
Dim testRng As Range

With Worksheets("sheet1")
Set myRng = .Range("a1", .Cells(.Rows.Count, "A").End(xlUp))

For Each myCell In myRng.Cells
Set testRng = Nothing
On Error Resume Next
Set testRng = Range(myCell.Value)
On Error GoTo 0
If testRng Is Nothing Then
MsgBox "not a range!"
Else
testRng.Interior.ColorIndex = 3
End If
Next myCell
End With

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top