Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 4
Default End(xlDown) not working?

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?
  #2   Report Post  
Posted to microsoft.public.excel.misc
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?



  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 4
Default End(xlDown) not working?

Thanks for the speedy rescue. I will give these suggestions a try to see
which is best suited to my problem. Actually B12 is the initial populated
cell in the column. I want to select B12 and all the continuously populated
cells in the column below B12 for formatting. This is VBA code in a
function attached to a form. I always find it a little tricky to get the
syntax exactly right - Excel isn't my primary skill! Thanks for the help.

"Bernie Deitrick" wrote:

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?




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Tracking Date/Actual Working Time Elapsed Jive Excel Worksheet Functions 1 September 25th 06 02:14 PM
Highlighted Reference Cell for a Working Cell Mr. Low Excel Worksheet Functions 0 June 22nd 06 04:27 PM
Sumproduct suddenly not working Andy Excel Discussion (Misc queries) 7 July 11th 05 10:56 PM
Calling another workbook not working malik641 Excel Worksheet Functions 2 June 24th 05 07:36 PM
how do I adjust working calendar (6 day work week) in excel that . Hatem Excel Worksheet Functions 1 January 25th 05 12:04 PM


All times are GMT +1. The time now is 12:18 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"