Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default VBA : Excel Range Selection Problem

I am experiencing a unique situation about the Excel Range. This is the
code :


Range(Cells(7, 6), Cells(7, intLastColumn).End(xlDown)).Select
Selection.NumberFormat = "0"

Its working most of the time and changing the format to "0" as desired.
(Columns will contain numerics only) But some times, For some wiered
reason, it wont reach till the last row. Anyone has similar experience.

Appreciate help.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 65
Default VBA : Excel Range Selection Problem

I prefer using the UsedRange property to determine the number of rows and
columns being used. Try replacing your first line of code with the following.

Range(cells(7,6),cells(7,usedrange.columns.count)) .select

http://HelpExcel.com

"Learner" wrote:

I am experiencing a unique situation about the Excel Range. This is the
code :


Range(Cells(7, 6), Cells(7, intLastColumn).End(xlDown)).Select
Selection.NumberFormat = "0"

Its working most of the time and changing the format to "0" as desired.
(Columns will contain numerics only) But some times, For some wiered
reason, it wont reach till the last row. Anyone has similar experience.

Appreciate help.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default VBA : Excel Range Selection Problem

Thanks for the reply!
Unfotunately, I got a Variable Not defined 'UsedRange' Error.
Am i mising something ?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 65
Default VBA : Excel Range Selection Problem

My fault. You probably have to include the Sheet object, e.g.,

SheetX.UsedRange.Columns.Count

http://HelpExcel.com

"Learner" wrote:

Thanks for the reply!
Unfotunately, I got a Variable Not defined 'UsedRange' Error.
Am i mising something ?


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default VBA : Excel Range Selection Problem

Thanks for the prompt repsonse.
I got it working with Activesheet.UsedRange
But it is selecting only ALL the columns...I am looking for something
that would select all the ROWS



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default VBA : Excel Range Selection Problem

if the last column has an empty cell, then you would have this problem.
does your last column have an empty cell within the last column in the data
you want to select?


Perhaps

Dim rng as Range
set rng = cells(rows.count,intLastColumn).End(xlup)
Range(Cells(7, 6), rng).Select
Selection.NumberFormat = "0"

or if Column 1 would be the best column to find the last filled row

Dim rng as Range
set rng = cells(rows.count,1).End(xlup)
Range(Cells(7, 6), Cells(rng.row, intLastColumn)).Select
Selection.NumberFormat = "0"

UsedRange is not always reliable for what you want to do, especially if you
will be deleting data at the bottom of your populated area.

--
Regards,
Tom Ogilvy

"Learner" wrote in message
oups.com...
Thanks for the prompt repsonse.
I got it working with Activesheet.UsedRange
But it is selecting only ALL the columns...I am looking for something
that would select all the ROWS



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default VBA : Excel Range Selection Problem

Exactly. it was the problem. I figured it just before I read this post.
Anyways, Thanks a million.

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
How do you do a range selection dialog like those many in Excel? LunaMoon Excel Discussion (Misc queries) 2 July 31st 08 04:22 PM
Range selection problem Brian Excel Programming 3 February 4th 05 01:56 PM
range selection problem derekc[_12_] Excel Programming 2 June 18th 04 04:41 PM
Excel VBA - Range(Selection, Selection.End(xlDown)).Name issue. jonH Excel Programming 3 June 7th 04 09:13 PM
Range selection problem SotjeRuud Excel Programming 1 August 27th 03 12:41 PM


All times are GMT +1. The time now is 02:23 AM.

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

About Us

"It's about Microsoft Excel"