VBA : Excel Range Selection Problem

  • Thread starter Thread starter Learner
  • Start date Start date
L

Learner

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.
 
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
 
Thanks for the reply!
Unfotunately, I got a Variable Not defined 'UsedRange' Error.
Am i mising something ?
 
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
 
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.
 
Exactly. it was the problem. I figured it just before I read this post.
Anyways, Thanks a million.
 

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