View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
Bernie Deitrick Bernie Deitrick is offline
external usenet poster
 
Posts: 5,441
Default End(xlDown) not working?

The Application object doesn't have a range property. Instead, use

Range("B12").Select
Range(Selection, Selection.End(xlDown)).Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With

But, better would be this, which would work on the active sheet, and
wouldn't cause problems if B12 is the last filled celll in column B:

With Range("B12", Cells(Rows.Count,2).End(xlUp))
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With

But better still might be this, which would work on a specific workbook and
worksheet no matter what sheet is active....

With Workbooks("Workbook Name.xls").Worksheets("Sheet Name")
With .Range("B12", Cells(Rows.Count,2).End(xlUp))
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
End With

HTH,
Bernie
MS Excel MVP

"RAHokie" wrote in message
...
I am using the following code to select a variable range of cells in a
column
for formatting.
ExcelSheet.Application.Range("B12").Select
ExcelSheet.Application.Range(Selection, Selection.End(xlDown)).Select
With ExcelSheet.Application.Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
I get a message that says "Object variable or with block variable not
set."
I suspect that my syntax may be slightly off somewhere. Any suggestions?