#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 191
Default Listbox

I have a listbox on a worksheet. When I leave the worksheet and go to
another worksheet or go to a userform from the worksheet and return back, how
do I make it so that none of the items in the listbox are selected?
Thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Listbox

If it is from the Control Toolbox and is single select:

Listbox1.ListIndex = -1

"ranswrt" wrote:

I have a listbox on a worksheet. When I leave the worksheet and go to
another worksheet or go to a userform from the worksheet and return back, how
do I make it so that none of the items in the listbox are selected?
Thanks

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 191
Default Listbox

I tried what you suggested and got

Run-time error '424':
object required

I tried

Sheets("Home").OLEObjects("ListBox1").ListIndex = -1
'Home' is the sheet that contains 'ListBox1'

I got this error

Run-time error '438':
Object doesn't support this property or method.

I put the listbox in using the control toolbox. Any Ideas as to what I am
doing wrong?

"JLGWhiz" wrote:

If it is from the Control Toolbox and is single select:

Listbox1.ListIndex = -1

"ranswrt" wrote:

I have a listbox on a worksheet. When I leave the worksheet and go to
another worksheet or go to a userform from the worksheet and return back, how
do I make it so that none of the items in the listbox are selected?
Thanks

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Listbox

Yes, I gave you as much as you gave me. You didn't say where it was located.
But by now, I thought you would know that you must specify the parent object
such as a sheet or a UserForm.

"ranswrt" wrote:

I tried what you suggested and got

Run-time error '424':
object required

I tried

Sheets("Home").OLEObjects("ListBox1").ListIndex = -1
'Home' is the sheet that contains 'ListBox1'

I got this error

Run-time error '438':
Object doesn't support this property or method.

I put the listbox in using the control toolbox. Any Ideas as to what I am
doing wrong?

"JLGWhiz" wrote:

If it is from the Control Toolbox and is single select:

Listbox1.ListIndex = -1

"ranswrt" wrote:

I have a listbox on a worksheet. When I leave the worksheet and go to
another worksheet or go to a userform from the worksheet and return back, how
do I make it so that none of the items in the listbox are selected?
Thanks

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Listbox

Sheerts("Home").ListBox1.ListIndex = -1

Will work with a Control Toolbox listbox but it does not go blank, it just
gives it a Null value. You can include a blank cell in your rowsource for
the first cell and use

Sheets("Home").ListBox1.ListIndex = 0

That will select the empty cell to display.

"ranswrt" wrote:

I tried what you suggested and got

Run-time error '424':
object required

I tried

Sheets("Home").OLEObjects("ListBox1").ListIndex = -1
'Home' is the sheet that contains 'ListBox1'

I got this error

Run-time error '438':
Object doesn't support this property or method.

I put the listbox in using the control toolbox. Any Ideas as to what I am
doing wrong?

"JLGWhiz" wrote:

If it is from the Control Toolbox and is single select:

Listbox1.ListIndex = -1

"ranswrt" wrote:

I have a listbox on a worksheet. When I leave the worksheet and go to
another worksheet or go to a userform from the worksheet and return back, how
do I make it so that none of the items in the listbox are selected?
Thanks



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 191
Default Listbox

Thanks I'll try that.

"JLGWhiz" wrote:

Sheerts("Home").ListBox1.ListIndex = -1

Will work with a Control Toolbox listbox but it does not go blank, it just
gives it a Null value. You can include a blank cell in your rowsource for
the first cell and use

Sheets("Home").ListBox1.ListIndex = 0

That will select the empty cell to display.

"ranswrt" wrote:

I tried what you suggested and got

Run-time error '424':
object required

I tried

Sheets("Home").OLEObjects("ListBox1").ListIndex = -1
'Home' is the sheet that contains 'ListBox1'

I got this error

Run-time error '438':
Object doesn't support this property or method.

I put the listbox in using the control toolbox. Any Ideas as to what I am
doing wrong?

"JLGWhiz" wrote:

If it is from the Control Toolbox and is single select:

Listbox1.ListIndex = -1

"ranswrt" wrote:

I have a listbox on a worksheet. When I leave the worksheet and go to
another worksheet or go to a userform from the worksheet and return back, how
do I make it so that none of the items in the listbox are selected?
Thanks

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 191
Default Listbox

I know there is an easy answer to this but I'm not getting it. I did a real
simple code to check this

Sub testlistbox()
Dim a As String
Sheets("Home").OLEObjects("ListBox1").ListIndex = -1
a = Sheets("Home").OLEObjects("ListBox1").Value
MsgBox (a)
End Sub

When I run this I get an error on the first line. I put a ' to skip the
first line and I get the same error. When I run this there is a item
highlighted in the listbox. The error I get in the two instances is:

Run-time error '438':
Object doesn't support this property or method.


I know there is an easy solution, but what am I doing wrong?



"JLGWhiz" wrote:

Sheerts("Home").ListBox1.ListIndex = -1

Will work with a Control Toolbox listbox but it does not go blank, it just
gives it a Null value. You can include a blank cell in your rowsource for
the first cell and use

Sheets("Home").ListBox1.ListIndex = 0

That will select the empty cell to display.

"ranswrt" wrote:

I tried what you suggested and got

Run-time error '424':
object required

I tried

Sheets("Home").OLEObjects("ListBox1").ListIndex = -1
'Home' is the sheet that contains 'ListBox1'

I got this error

Run-time error '438':
Object doesn't support this property or method.

I put the listbox in using the control toolbox. Any Ideas as to what I am
doing wrong?

"JLGWhiz" wrote:

If it is from the Control Toolbox and is single select:

Listbox1.ListIndex = -1

"ranswrt" wrote:

I have a listbox on a worksheet. When I leave the worksheet and go to
another worksheet or go to a userform from the worksheet and return back, how
do I make it so that none of the items in the listbox are selected?
Thanks

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Listbox

Worksheets("Home").OLEObjects("ListBox1").Object.L istIndex = -1

But if you set the .listindex to -1, then the next line (.value) won't work.

Option Explicit
Sub testlistbox()
Dim a As String

With Worksheets("Home").OLEObjects("ListBox1").Object
.ListIndex = -1 'or 3
If .ListIndex < 0 Then
a = "Nothing chosen"
Else
a = .Value
End If
End With
MsgBox a
End Sub


ranswrt wrote:

I know there is an easy answer to this but I'm not getting it. I did a real
simple code to check this

Sub testlistbox()
Dim a As String
Sheets("Home").OLEObjects("ListBox1").ListIndex = -1
a = Sheets("Home").OLEObjects("ListBox1").Value
MsgBox (a)
End Sub

When I run this I get an error on the first line. I put a ' to skip the
first line and I get the same error. When I run this there is a item
highlighted in the listbox. The error I get in the two instances is:

Run-time error '438':
Object doesn't support this property or method.


I know there is an easy solution, but what am I doing wrong?

"JLGWhiz" wrote:

Sheerts("Home").ListBox1.ListIndex = -1

Will work with a Control Toolbox listbox but it does not go blank, it just
gives it a Null value. You can include a blank cell in your rowsource for
the first cell and use

Sheets("Home").ListBox1.ListIndex = 0

That will select the empty cell to display.

"ranswrt" wrote:

I tried what you suggested and got

Run-time error '424':
object required

I tried

Sheets("Home").OLEObjects("ListBox1").ListIndex = -1
'Home' is the sheet that contains 'ListBox1'

I got this error

Run-time error '438':
Object doesn't support this property or method.

I put the listbox in using the control toolbox. Any Ideas as to what I am
doing wrong?

"JLGWhiz" wrote:

If it is from the Control Toolbox and is single select:

Listbox1.ListIndex = -1

"ranswrt" wrote:

I have a listbox on a worksheet. When I leave the worksheet and go to
another worksheet or go to a userform from the worksheet and return back, how
do I make it so that none of the items in the listbox are selected?
Thanks


--

Dave Peterson
  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 191
Default Listbox

Thanks that explains it better

"Dave Peterson" wrote:

Worksheets("Home").OLEObjects("ListBox1").Object.L istIndex = -1

But if you set the .listindex to -1, then the next line (.value) won't work.

Option Explicit
Sub testlistbox()
Dim a As String

With Worksheets("Home").OLEObjects("ListBox1").Object
.ListIndex = -1 'or 3
If .ListIndex < 0 Then
a = "Nothing chosen"
Else
a = .Value
End If
End With
MsgBox a
End Sub


ranswrt wrote:

I know there is an easy answer to this but I'm not getting it. I did a real
simple code to check this

Sub testlistbox()
Dim a As String
Sheets("Home").OLEObjects("ListBox1").ListIndex = -1
a = Sheets("Home").OLEObjects("ListBox1").Value
MsgBox (a)
End Sub

When I run this I get an error on the first line. I put a ' to skip the
first line and I get the same error. When I run this there is a item
highlighted in the listbox. The error I get in the two instances is:

Run-time error '438':
Object doesn't support this property or method.


I know there is an easy solution, but what am I doing wrong?

"JLGWhiz" wrote:

Sheerts("Home").ListBox1.ListIndex = -1

Will work with a Control Toolbox listbox but it does not go blank, it just
gives it a Null value. You can include a blank cell in your rowsource for
the first cell and use

Sheets("Home").ListBox1.ListIndex = 0

That will select the empty cell to display.

"ranswrt" wrote:

I tried what you suggested and got

Run-time error '424':
object required

I tried

Sheets("Home").OLEObjects("ListBox1").ListIndex = -1
'Home' is the sheet that contains 'ListBox1'

I got this error

Run-time error '438':
Object doesn't support this property or method.

I put the listbox in using the control toolbox. Any Ideas as to what I am
doing wrong?

"JLGWhiz" wrote:

If it is from the Control Toolbox and is single select:

Listbox1.ListIndex = -1

"ranswrt" wrote:

I have a listbox on a worksheet. When I leave the worksheet and go to
another worksheet or go to a userform from the worksheet and return back, how
do I make it so that none of the items in the listbox are selected?
Thanks


--

Dave Peterson

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
userform listbox cannot get listbox.value to transfer back to main sub [email protected] Excel Programming 1 May 17th 06 09:44 PM
avoiding duplicates in listbox (added from another listbox) KR Excel Programming 4 March 14th 06 08:17 PM
VBA: Creating listbox similar to the one in Pivot table (Listbox+Checkbox) modjoe23 Excel Programming 3 August 18th 05 02:35 PM
listbox.value not equal to listbox.list(listbox.listindex,0) ARB Excel Programming 0 October 22nd 03 12:46 AM
Is refreshing listbox rowsource in listbox click event possible? Jeremy Gollehon[_2_] Excel Programming 4 September 25th 03 06:45 PM


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