Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default Selection.count isnt working

I am testing a macro and I cant figure out what I'm doing wrong. I have
named a range, dvec, that contains contiguous data. I want to pass the
number of data points, n, to the array cvec(n). To test this I inserted the
MsgBox line. When I run this macro, I get the number of rows in the range
dvec rather than the count of data points. What am I doing wrong? I have
made sure all blank cells in the range are clear.

Option Base 1
Sub SelectCount()
'Re-Dim data array cvec
Dim n, cvec
Sheets("Sheet2").Range("dvec").Select
n = Selection.Count
ReDim cvec(n)
MsgBox "The size of vector cvec is " & n
End Sub

TIA

Steve H


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Selection.count isnt working

Steve,

I am not sure what you are referring to when you say points, but I get the
number of cells, not the number of rows, as I would have expected.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

wrote in message
...
I am testing a macro and I cant figure out what I'm doing wrong. I have
named a range, dvec, that contains contiguous data. I want to pass the
number of data points, n, to the array cvec(n). To test this I inserted

the
MsgBox line. When I run this macro, I get the number of rows in the range
dvec rather than the count of data points. What am I doing wrong? I have
made sure all blank cells in the range are clear.

Option Base 1
Sub SelectCount()
'Re-Dim data array cvec
Dim n, cvec
Sheets("Sheet2").Range("dvec").Select
n = Selection.Count
ReDim cvec(n)
MsgBox "The size of vector cvec is " & n
End Sub

TIA

Steve H




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Selection.count isnt working

I agree with Bob. If this is a single column range, the number of cells,
number of rows and number of data points should all agree. It is unclear
how data points differ from the number of cells/rows. If it is multicolumn
(single area), then you just want the number of rows

n = Selection.Rows.count

However, if the end result is to pick up the data in the range to the array

Option Base 1
Sub SelectCount()
Dim n, cvec
cvec = Range("dvec").Value

MsgBox "The size of vector cvec is 1 x " & UBound(cvec, 1) _
& ", 1 x " & UBound(cvec, 2)
sStr = ""
For i = 1 To UBound(cvec, 1)
For j = 1 To UBound(cvec, 2)
sStr = sStr & cvec(i, j) & ", "
Next
sStr = sStr & vbNewLine
Next
MsgBox sStr
End Sub

Using this method to pick up your data, the variable must be a variant, and
it will produce a 2-D array even if you are picking up a single column or
single row.

A msgbox is limited to 255 characters I believe, so if you array is large,
the demo will not display its elements.

--
Regards,
Tom Ogilvy





wrote in message
...
I am testing a macro and I cant figure out what I'm doing wrong. I have
named a range, dvec, that contains contiguous data. I want to pass the
number of data points, n, to the array cvec(n). To test this I inserted

the
MsgBox line. When I run this macro, I get the number of rows in the range
dvec rather than the count of data points. What am I doing wrong? I have
made sure all blank cells in the range are clear.

Option Base 1
Sub SelectCount()
'Re-Dim data array cvec
Dim n, cvec
Sheets("Sheet2").Range("dvec").Select
n = Selection.Count
ReDim cvec(n)
MsgBox "The size of vector cvec is " & n
End Sub

TIA

Steve H




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
Nested IF isnt working right..Why? Curtis Excel Worksheet Functions 1 October 30th 09 10:08 PM
Conditional Formatting isnt working right changetires Excel Discussion (Misc queries) 6 June 28th 06 08:47 PM
autofilter isnt working john mcmichael Excel Discussion (Misc queries) 2 October 19th 05 07:53 PM
Function isnt working, just displays the formula in cell?eg A2+B2 ru Excel Discussion (Misc queries) 1 September 30th 05 01:35 PM
AutoFill isnt working? M.L Excel Discussion (Misc queries) 7 June 16th 05 08:58 PM


All times are GMT +1. The time now is 09:34 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"