Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 36
Default Help with Selection Property

Hi
I have the following cod
Dim count1 As Intege
Worksheets("ABC").Activat
ActiveSheet.Range("AR:AR").Selec
count1 = Selection.Column.coun
For i = 1 To count
ComboBox15.AddItem CStr(Sheet1.Range("AR" + CStr(i)).Value
Nex

I want to know the last row number in column AR that contains the data (Column AR has blank cells too ) and run the loop equal number of times.
But every time I run this code, it gives an error on line "count1 = Selection.Column.count
Plz hel
Thnks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default Help with Selection Property

Hi
try something like the following:
Sub count_rows()
Dim RowNdx As Long
Dim LastRow As Long

LastRow = worksheets("ABC").Cells(Rows.Count, "AR").End(xlUp).row
For RowNdx = LastRow To 1 Step -1
If Cells(RowNdx, "AR").Value < "" Then
ComboBox15.AddItem CStr(Cells(RowNdx, "AR").Value)
End If
Next RowNdx
End Sub

--
Regards
Frank Kabel
Frankfurt, Germany


Shilps wrote:
Hi,
I have the following code
Dim count1 As Integer
Worksheets("ABC").Activate
ActiveSheet.Range("AR:AR").Select
count1 = Selection.Column.count
For i = 1 To count1
ComboBox15.AddItem CStr(Sheet1.Range("AR" + CStr(i)).Value)
Next

I want to know the last row number in column AR that contains the
data (Column AR has blank cells too ) and run the loop equal number
of times. But every time I run this code, it gives an error on line
"count1 = Selection.Column.count"
Plz help
Thnks

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Help with Selection Property

Hi Ships,

Even if you got the syntax correct, it would not work as you are counting
the columns in a range. As the range is just one column, this would always
be 1. You need to count the rows, like so

Worksheets("Sheet1").Activate
For i = 1 To ActiveSheet.Cells(Rows.Count, "AR").End(xlUp).Row
ComboBox15.AddItem CStr(Sheet1.Range("AR" + CStr(i)).Value)
Next

--

HTH

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

"Shilps" wrote in message
...
Hi,
I have the following code
Dim count1 As Integer
Worksheets("ABC").Activate
ActiveSheet.Range("AR:AR").Select
count1 = Selection.Column.count
For i = 1 To count1
ComboBox15.AddItem CStr(Sheet1.Range("AR" + CStr(i)).Value)
Next

I want to know the last row number in column AR that contains the data

(Column AR has blank cells too ) and run the loop equal number of times.
But every time I run this code, it gives an error on line "count1 =

Selection.Column.count"
Plz help
Thnks



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 391
Default Help with Selection Property

a slightly easier method...assumes the ActiveX combo...

Sub SetCombo()

With Worksheets("Sheet1")
.ComboBox15.ListFillRange = _
"E2:E" & .Range("E5000").End(xlUp).Row
End With

End Sub

This sets the combo to a table starting in row 2 with an
indeterminate number of rows

HTH
Patrick Molloy
Microsoft Excel MVP
-------------------
I Feel Great!

-----Original Message-----
Hi,
I have the following code
Dim count1 As Integer
Worksheets("ABC").Activate
ActiveSheet.Range("AR:AR").Select
count1 = Selection.Column.count
For i = 1 To count1
ComboBox15.AddItem CStr(Sheet1.Range("AR" + CStr

(i)).Value)
Next

I want to know the last row number in column AR that

contains the data (Column AR has blank cells too ) and
run the loop equal number of times.
But every time I run this code, it gives an error on

line "count1 = Selection.Column.count"
Plz help
Thnks
.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 36
Default Help with Selection Property

Hi Bob

As U said that I am trying to count the rows, I chaged the code to following
Dim c As Intege
Worksheets("ABC").Activat
ActiveSheet.Range("AR:AR").Selec
c1 = Selection.Rows.Coun
For c = 2 To c
ComboBox15.AddItem CStr(Sheet1.Range("AR" + CStr(c)).Value
Next

But now it is giving error on lin
For c = 2 To c

But it is not giving error when I change the code t

Dim c As Intege
Worksheets("ABC").Activat
ActiveSheet.Range("AR:AR").Selec
c1 = MsgBox(Selection.Rows.Count, , no
For c = 2 To c
ComboBox15.AddItem CStr(Sheet1.Range("AR" + CStr(c)).Value
Next

How does adding a msgbox statement change it
Also if I change the code to, it gives error on "ComboBox15.AddItem CStr(Sheet1.Range("AR" + CStr(c)).Value)

Dim c As Lon
Worksheets("ABC").Activat
ActiveSheet.Range("AR:AR").Selec
c1 = Selection.Rows.Coun
For c = 2 To c
ComboBox15.AddItem CStr(Sheet1.Range("AR" + CStr(c)).Value
Next

TI
Shilps


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Help with Selection Property

Hi Shilps,

I don't know why it gives an error, but it is not good as it returns all of
the rows, that is 65536. You don't want this. What you want is

c1 = Cells(Rows.Count, "AR").End(xlUp).Row

try that and see if you still a combo error.
--

HTH

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

"Shilps" wrote in message
...
Hi Bob!

As U said that I am trying to count the rows, I chaged the code to

following :
Dim c As Integer
Worksheets("ABC").Activate
ActiveSheet.Range("AR:AR").Select
c1 = Selection.Rows.Count
For c = 2 To c1
ComboBox15.AddItem CStr(Sheet1.Range("AR" + CStr(c)).Value)
Next c

But now it is giving error on line
For c = 2 To c1

But it is not giving error when I change the code to

Dim c As Integer
Worksheets("ABC").Activate
ActiveSheet.Range("AR:AR").Select
c1 = MsgBox(Selection.Rows.Count, , no)
For c = 2 To c1
ComboBox15.AddItem CStr(Sheet1.Range("AR" + CStr(c)).Value)
Next c

How does adding a msgbox statement change it?
Also if I change the code to, it gives error on "ComboBox15.AddItem

CStr(Sheet1.Range("AR" + CStr(c)).Value)"

Dim c As Long
Worksheets("ABC").Activate
ActiveSheet.Range("AR:AR").Select
c1 = Selection.Rows.Count
For c = 2 To c1
ComboBox15.AddItem CStr(Sheet1.Range("AR" + CStr(c)).Value)
Next c

TIH
Shilps



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
Limiting selection in a cell AND linking that selection to a list Lisa Excel Discussion (Misc queries) 1 July 28th 09 05:00 PM
Copy Selection - Transpose Selection - Delete Selection Uninvisible Excel Discussion (Misc queries) 2 October 23rd 07 04:18 PM
Identifying a selection of a selection of a range swimfast Excel Worksheet Functions 1 March 1st 07 02:51 AM
limit cell list selection based on the selection of another list lorraine Excel Worksheet Functions 2 December 14th 04 08:17 PM
How to find what object type is returned from Selection property ? Krzysztof Klimczak[_3_] Excel Programming 1 October 2nd 03 11:33 PM


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