#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default UsedRange

Hi Y'all.

One of my subs clears the contents of a worksheet then pastes in new data. I
then concatenate the text in columns A & B in column H by going:
--------------
Set ur = ActiveSheet.UsedRange

For Each c In Range("A2:A" & ur.Rows.Count)
Cells(c.Row, 8) = Cells(c.Row, 1) & Cells(c.Row, 2)
Next c
--------------

The trouble is that there are 135 rows of data (the pasted data occupies
A1:G135), but ActiveSheet.UsedRange.Rows.Count only returns 134. Any ideas?
Sure I can add 1 but I'd like to know if I'm mis-using this property.

cheers

Damo


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default UsedRange

Are you sure that there's anything in row 1?

If your data were in A2:a135, then the ur.rows.count would be 134.

Usedrange doesn't always start in A1.

maybe:
dim LastRow as long
with activesheet.usedrange
LastRow = .rows(.rows.count).row
end with

then
For Each c In Range("A2:A" & ur.Rows.Count)
becomes
For Each c In Range("A2:A" & LastRow)

On the other hand, I like to just find a column that I know is always filled
(say column A). Then work from the bottom up:

dim Lastrow as long
with activesheet
lastrow = .cells(.rows.count,"A").end(xlup).row
end with



Damien McBain wrote:

Hi Y'all.

One of my subs clears the contents of a worksheet then pastes in new data. I
then concatenate the text in columns A & B in column H by going:
--------------
Set ur = ActiveSheet.UsedRange

For Each c In Range("A2:A" & ur.Rows.Count)
Cells(c.Row, 8) = Cells(c.Row, 1) & Cells(c.Row, 2)
Next c
--------------

The trouble is that there are 135 rows of data (the pasted data occupies
A1:G135), but ActiveSheet.UsedRange.Rows.Count only returns 134. Any ideas?
Sure I can add 1 but I'd like to know if I'm mis-using this property.

cheers

Damo


--

Dave Peterson

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default UsedRange

Spot on Dave, there was nothing in row 1. I incorrectly assumed that
UsedRange started at A1.

cheers & thanks,

Damo

Dave Peterson wrote:
Are you sure that there's anything in row 1?

If your data were in A2:a135, then the ur.rows.count would be 134.

Usedrange doesn't always start in A1.

maybe:
dim LastRow as long
with activesheet.usedrange
LastRow = .rows(.rows.count).row
end with

then
For Each c In Range("A2:A" & ur.Rows.Count)
becomes
For Each c In Range("A2:A" & LastRow)

On the other hand, I like to just find a column that I know is always
filled (say column A). Then work from the bottom up:

dim Lastrow as long
with activesheet
lastrow = .cells(.rows.count,"A").end(xlup).row
end with



Damien McBain wrote:

Hi Y'all.

One of my subs clears the contents of a worksheet then pastes in new
data. I then concatenate the text in columns A & B in column H by
going: --------------
Set ur = ActiveSheet.UsedRange

For Each c In Range("A2:A" & ur.Rows.Count)
Cells(c.Row, 8) = Cells(c.Row, 1) & Cells(c.Row, 2)
Next c
--------------

The trouble is that there are 135 rows of data (the pasted data
occupies A1:G135), but ActiveSheet.UsedRange.Rows.Count only returns
134. Any ideas? Sure I can add 1 but I'd like to know if I'm
mis-using this property.

cheers

Damo




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
SpecialCells and UsedRange Norm[_5_] Excel Programming 2 April 1st 04 06:53 PM
usedrange doesn't show the right value Karin S Excel Programming 1 March 6th 04 07:36 PM
UsedRange problem Kobayashi[_26_] Excel Programming 4 January 30th 04 05:17 PM
UsedRange problem Andy Excel Programming 2 September 18th 03 05:17 PM
Usedrange Terry VanDuzee Excel Programming 6 August 10th 03 05:57 PM


All times are GMT +1. The time now is 03:28 PM.

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"