Welcome to the { mindfrost82.com } forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.

Go Back   { mindfrost82.com } > Gadget Corner > Tech Newsgroups > Microsoft > MS Office > Excel

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-27-2007, 12:39 AM
Rob W
 
Posts: n/a
Userform - Combo box with Range unexpected results ...

Greetings,

The following code below finds empty cells in any of the columns and selects
the entire row.
When I run the code and run the range name.select I can see its selected all
the rows with a blank cell value in them.


Private Sub UserForm_Initialize()

Dim patientList As Range
Set patientList =
Sheets("Data").Range("A:A,D:D,E:E,F:F,G:G").Curren tRegion
Set patientList = patientList.SpecialCells(xlCellTypeBlanks).EntireR ow
patientList.Select
Me.comboPatient.RowSource = patientList.Columns(1).Address

End Sub

However when I populate my RowSoure (combo box) its only ever populates one
value (The first row it sees with a blank cell value)?
If i remove the line which find blank cells it lists all the values in
column A rather than the selection I require (any rows with blank values I
want to appear in the combo)

Can anyone please please help me, Im going crazy !!!

Thanks
Rob W







Reply With Quote
  #2 (permalink)  
Old 11-27-2007, 02:46 AM
Jim Cone
 
Posts: n/a
Re: Userform - Combo box with Range unexpected results ...


When you have a multi area range you must specify each area
or you only get the first area returned.
Looping thru the areas is the common solution.
Here is my test code which seems to work.
Maybe it will be of some help.
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)
'---

Sub Where()
Dim patientList As Range
Dim rngArea As Range
Dim colList As Collection

Set colList = New Collection
Set patientList = _
Application.Union(Sheets("Data").Range("A:A"), Sheets("Data").Range("D:G"))
Set patientList = _
Application.Intersect(Sheets("Data").UsedRange, patientList)
Set patientList = patientList.SpecialCells(xlCellTypeBlanks)

For Each rngArea In patientList
On Error Resume Next
'Error if a duplicate
colList.Add vbNullString, CStr(rngArea.Row)
If Err.Number = 0 Then
UserForm1.ComboBox1.AddItem "Row " & rngArea.Row
End If
Next
UserForm1.Show
Unload UserForm1
Set colList = Nothing
End Sub
'---



"Rob W"
wrote in message
Greetings,
The following code below finds empty cells in any of the columns and selects
the entire row.
When I run the code and run the range name.select I can see its selected all
the rows with a blank cell value in them.

Private Sub UserForm_Initialize()
Dim patientList As Range
Set patientList =
Sheets("Data").Range("A:A,D:D,E:E,F:F,G:G").Curren tRegion
Set patientList = patientList.SpecialCells(xlCellTypeBlanks).EntireR ow
patientList.Select
Me.comboPatient.RowSource = patientList.Columns(1).Address
End Sub

However when I populate my RowSoure (combo box) its only ever populates one
value (The first row it sees with a blank cell value)?
If i remove the line which find blank cells it lists all the values in
column A rather than the selection I require (any rows with blank values I
want to appear in the combo)
Can anyone please please help me, Im going crazy !!!
Thanks
Rob W
Reply With Quote
  #3 (permalink)  
Old 11-27-2007, 12:27 PM
Rob W
 
Posts: n/a
Re: Userform - Combo box with Range unexpected results ...

Thanks very useful, Ive only just got round to looking at the reply (UK
based)

I came up with something similar

Dim lRowEnd As Long
Dim R As Range
Dim wsData As Worksheet

Set wsData = Sheets("Data")
lRowEnd = wsData.Cells(Rows.Count, "A").End(xlUp).Row
With comboPatient
.Clear
For Each R In wsData.Range("E1:E" &
lRowEnd).SpecialCells(xlCellTypeBlanks)
.AddItem CStr(wsData.Cells(R.Row, "A").Value)
Next R
End With

I will look into your solution in more detail later, thanks again.
I havent used collections before so it should be interesting ..

Cheers
Rob W



"Jim Cone" <jim.coneXXX@rcn.comXXX> wrote in message
news:%23saYr%23JMIHA.5224@TK2MSFTNGP02.phx.gbl...
>
> When you have a multi area range you must specify each area
> or you only get the first area returned.
> Looping thru the areas is the common solution.
> Here is my test code which seems to work.
> Maybe it will be of some help.
> --
> Jim Cone
> San Francisco, USA
> http://www.realezsites.com/bus/primitivesoftware
> (Excel Add-ins / Excel Programming)
> '---
>
> Sub Where()
> Dim patientList As Range
> Dim rngArea As Range
> Dim colList As Collection
>
> Set colList = New Collection
> Set patientList = _
> Application.Union(Sheets("Data").Range("A:A"),
> Sheets("Data").Range("D:G"))
> Set patientList = _
> Application.Intersect(Sheets("Data").UsedRange, patientList)
> Set patientList = patientList.SpecialCells(xlCellTypeBlanks)
>
> For Each rngArea In patientList
> On Error Resume Next
> 'Error if a duplicate
> colList.Add vbNullString, CStr(rngArea.Row)
> If Err.Number = 0 Then
> UserForm1.ComboBox1.AddItem "Row " & rngArea.Row
> End If
> Next
> UserForm1.Show
> Unload UserForm1
> Set colList = Nothing
> End Sub
> '---
>
>
>
> "Rob W"
> wrote in message
> Greetings,
> The following code below finds empty cells in any of the columns and
> selects
> the entire row.
> When I run the code and run the range name.select I can see its selected
> all
> the rows with a blank cell value in them.
>
> Private Sub UserForm_Initialize()
> Dim patientList As Range
> Set patientList =
> Sheets("Data").Range("A:A,D:D,E:E,F:F,G:G").Curren tRegion
> Set patientList = patientList.SpecialCells(xlCellTypeBlanks).EntireR ow
> patientList.Select
> Me.comboPatient.RowSource = patientList.Columns(1).Address
> End Sub
>
> However when I populate my RowSoure (combo box) its only ever populates
> one
> value (The first row it sees with a blank cell value)?
> If i remove the line which find blank cells it lists all the values in
> column A rather than the selection I require (any rows with blank values I
> want to appear in the combo)
> Can anyone please please help me, Im going crazy !!!
> Thanks
> Rob W



Reply With Quote
Reply

  { mindfrost82.com } > Gadget Corner > Tech Newsgroups > Microsoft > MS Office > Excel


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 06:03 PM.


Powered by vBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.
© 1999-2008 mindfrost82.com v11.0


Sponsors:
Valentine's Day Gifts | The eBay Song | Child Trust Funds | Debt Help | Credit Cards



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114