kelly mort
Well-known Member
- Joined
- Apr 10, 2017
- Messages
- 2,169
- Office Version
- 2016
- Platform
- Windows
Hi,
I came up with this code online, it's not doing exactly what I wanted.
I need someone fix it for me.
This is what I want:
I want to load non blank cells from the column B into the listbox
It's filling then breaking at the blanks.
It can't pick it as I wanted.
I came up with this code online, it's not doing exactly what I wanted.
I need someone fix it for me.
This is what I want:
I want to load non blank cells from the column B into the listbox
Code:
<code style="box-sizing: inherit; margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; vertical-align: baseline; max-height: 300px; overflow: auto;">[COLOR=#101094]Sub[/COLOR][COLOR=#303336] LoadNonBlanks[/COLOR][COLOR=#303336]()[/COLOR][COLOR=#303336]
[/COLOR][COLOR=#101094]Dim[/COLOR][COLOR=#303336] rng [/COLOR][COLOR=#101094]As[/COLOR][COLOR=#303336] Range[/COLOR][COLOR=#303336],[/COLOR][COLOR=#303336] r [/COLOR][COLOR=#101094]As[/COLOR][COLOR=#303336] Range[/COLOR][COLOR=#303336],[/COLOR][COLOR=#303336] rSel [/COLOR][COLOR=#101094]As[/COLOR][COLOR=#303336] Range
Dim arr As Variant
[/COLOR][COLOR=#101094]Set[/COLOR][COLOR=#303336] rng [/COLOR][COLOR=#303336]=[/COLOR][COLOR=#303336] Range[/COLOR][COLOR=#303336]([/COLOR][COLOR=#7D2727]"B3:B103"[/COLOR][COLOR=#303336])[/COLOR][COLOR=#303336]
[/COLOR][COLOR=#101094]Set[/COLOR][COLOR=#303336] rSel [/COLOR][COLOR=#303336]=[/COLOR][COLOR=#7D2727]Nothing[/COLOR][COLOR=#303336]
[/COLOR][COLOR=#101094]For[/COLOR][COLOR=#101094]Each[/COLOR][COLOR=#303336] r [/COLOR][COLOR=#101094]In[/COLOR][COLOR=#303336] rng
[/COLOR][COLOR=#101094]If[/COLOR][COLOR=#303336] r[/COLOR][COLOR=#303336].[/COLOR][COLOR=#303336]Value [/COLOR][COLOR=#303336]<>[/COLOR][COLOR=#7D2727]""[/COLOR][COLOR=#101094]Then[/COLOR][COLOR=#303336]
[/COLOR][COLOR=#101094]If[/COLOR][COLOR=#303336] rSel [/COLOR][COLOR=#101094]Is[/COLOR][COLOR=#7D2727]Nothing[/COLOR][COLOR=#101094]Then[/COLOR][COLOR=#303336]
[/COLOR][COLOR=#101094]Set[/COLOR][COLOR=#303336] rSel [/COLOR][COLOR=#303336]=[/COLOR][COLOR=#303336] r
[/COLOR][COLOR=#101094]Else[/COLOR][COLOR=#303336]
[/COLOR][COLOR=#101094]Set[/COLOR][COLOR=#303336] rSel [/COLOR][COLOR=#303336]=[/COLOR][COLOR=#303336] Union[/COLOR][COLOR=#303336]([/COLOR][COLOR=#303336]rSel[/COLOR][COLOR=#303336],[/COLOR][COLOR=#303336] r[/COLOR][COLOR=#303336])[/COLOR][COLOR=#303336]
[/COLOR][COLOR=#101094]End[/COLOR][COLOR=#101094]If[/COLOR][COLOR=#303336]
[/COLOR][COLOR=#101094]End[/COLOR][COLOR=#101094]If[/COLOR][COLOR=#303336]
[/COLOR][COLOR=#101094]Next[/COLOR][COLOR=#303336] r
[/COLOR][COLOR=#101094]If[/COLOR][COLOR=#101094]Not[/COLOR][COLOR=#303336] rSel [/COLOR][COLOR=#101094]Is[/COLOR][COLOR=#7D2727]Nothing[/COLOR][COLOR=#101094]Then[/COLOR][COLOR=#303336] arr = rSel
[/COLOR][COLOR=#303336] MyCmb.clear
MyCmb.List = arr
[/COLOR][COLOR=#101094]End[/COLOR][COLOR=#101094]Sub[/COLOR]</code>
It's filling then breaking at the blanks.
It can't pick it as I wanted.