View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Charles Chickering Charles Chickering is offline
external usenet poster
 
Posts: 272
Default Need help with Range object in Macro programming

Dan, there is nothing magical about using Range vs using Cells, the
difference is whether or not you select the cell, so as Gary, Paul, and Jim
have shown you don't need to use the Range object, if you would like to use
Range it can be done this way:
With Range("G" & x)
.Font.Bold = True
.Interior.ColorIndex = 6
End With
--
Charles Chickering

"A good example is twice the value of good advice."


"Dan" wrote:

I have a macro that puts data into a sheet and sets the font to bold and
color to yellow. It looks like this:

Cells(x, 7).Select
Selection.Font.Bold = True
Selection.Interior.ColorIndex = 6

I was reading some websites that say this is not efficient, that I should
use with:
example:

With Range("A1")
.Font.Bold = True
.Interior.ColorIndex = 6
End With

Since my code is in a loop I use Cells(x,7). How do I format the Range
object to use a variable instead of "A1"? I tried Range(Cells(x,7)) but got
an error.

Dan