Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 127
Default range problem

Dear Experts,
I am trying to populate a combobox in a userform with data looked up from a
worksheet. Here is the code:

Private Sub Userform_Initialize()
Dim rng As Range
Dim End_Row As Integer
Dim Begin_Row As Integer
Dim i As Integer
i = 0
Do
i = i + 1
Loop Until Worksheets("Data").Cells(i, 1) = Worksheets("Choix").Cells(4, 1)
Begin_Row = i

Do
i = i + 1
Loop Until Worksheets("Data").Cells(i, 1) < Worksheets("Choix").Cells(4, 1)
End_Row = i - 1

Set rng = Range((Worksheets("Data").Range("B", Begin_Row)),
Worksheets("Data").Range("B", End_Row))

Me.ComboBox1.List = rng.Value

End Sub


However I always get an error when I get to "set rng".
Can you please help me? I am using excel 2003.
Thanks!
Kind regards
--
Valeria
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default range problem

The syntax for your Range property call is not correct. Change the commas to
ampersands...

Set rng = Range(Worksheets("Data").Range("B" & Begin_Row), _
Worksheets("Data").Range("B" & End_Row))

Or, you can use the Cells property instead of the Range property which does
use the structure you attempted (but with the row value coming first and the
column value last) in order to avoid the concatenations...

Set rng = Range(Worksheets("Data").Cells(Begin_Row, "B"), _
Worksheets("Data").Cells(End_Row, "B"))

--
Rick (MVP - Excel)


"Valeria" wrote in message
...
Dear Experts,
I am trying to populate a combobox in a userform with data looked up from
a
worksheet. Here is the code:

Private Sub Userform_Initialize()
Dim rng As Range
Dim End_Row As Integer
Dim Begin_Row As Integer
Dim i As Integer
i = 0
Do
i = i + 1
Loop Until Worksheets("Data").Cells(i, 1) = Worksheets("Choix").Cells(4,
1)
Begin_Row = i

Do
i = i + 1
Loop Until Worksheets("Data").Cells(i, 1) < Worksheets("Choix").Cells(4,
1)
End_Row = i - 1

Set rng = Range((Worksheets("Data").Range("B", Begin_Row)),
Worksheets("Data").Range("B", End_Row))

Me.ComboBox1.List = rng.Value

End Sub


However I always get an error when I get to "set rng".
Can you please help me? I am using excel 2003.
Thanks!
Kind regards
--
Valeria


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default range problem

Hi,

Try this

Private Sub Userform_Initialize()
Dim End_Row As Long
Dim Begin_Row As Long
Dim i As Long
i = 0
Do
i = i + 1
Loop Until Worksheets("Data").Cells(i, 1) _
= Worksheets("Choix").Cells(4, 1)
Begin_Row = i
Do
i = i + 1
Loop Until Worksheets("Data").Cells(i, 1) _
< Worksheets("Choix").Cells(4, 1)
End_Row = i - 1
Me.ComboBox1.List = Worksheets("Data").Range( _
"B" & Begin_Row & ":B" & End_Row).Value
End Sub


Mike

"Valeria" wrote:

Dear Experts,
I am trying to populate a combobox in a userform with data looked up from a
worksheet. Here is the code:

Private Sub Userform_Initialize()
Dim rng As Range
Dim End_Row As Integer
Dim Begin_Row As Integer
Dim i As Integer
i = 0
Do
i = i + 1
Loop Until Worksheets("Data").Cells(i, 1) = Worksheets("Choix").Cells(4, 1)
Begin_Row = i

Do
i = i + 1
Loop Until Worksheets("Data").Cells(i, 1) < Worksheets("Choix").Cells(4, 1)
End_Row = i - 1

Set rng = Range((Worksheets("Data").Range("B", Begin_Row)),
Worksheets("Data").Range("B", End_Row))

Me.ComboBox1.List = rng.Value

End Sub


However I always get an error when I get to "set rng".
Can you please help me? I am using excel 2003.
Thanks!
Kind regards
--
Valeria

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
Find function for a Range failing in excel 2003 and giving subscriptout of range error 9 problem but works fine in excel 2000 Prince Excel Programming 5 February 10th 09 05:47 PM
Range Problem Steven Drenker[_4_] Excel Programming 5 January 23rd 06 07:15 PM
Range Problem jesmin Excel Discussion (Misc queries) 19 December 19th 05 12:11 AM
Range problem David Goodall[_2_] Excel Programming 1 October 8th 05 10:45 AM
range problem [email protected] Excel Programming 1 April 9th 04 09:47 AM


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