Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 206
Default ListBox2.AddItem ListBox1.Value becomes a String when being Integer?

Hi Bob, Tom, ...all other Helping Hands,

I am reading in values (integers & strings) in listbox1 as follows:
UserForm1.ListBox1.AddItem Sheets("Sheet1").Cells(Userrange.row,
kolom)

I make a selection out of Listbox1 into Listbox2 as in sub:
AddButton_Click()

===Does my Integer gets converted into String with:
ListBox2.AddItem ListBox1.Value ????

and therefore cannot find the Integer in the
"Application.Match(ListBox2.List(i), Range(Userrange.Address),
0)"-function?!

How to get the same cell "formats" in listbox2 as in listbox1?
Sige


Private Sub AddButton_Click()
Dim i As Integer
If ListBox1.ListIndex = -1 Then Exit Sub
If Not cbDuplicates Then
' See if item already exists
For i = 0 To ListBox2.ListCount - 1
If ListBox1.Value = ListBox2.List(i) Then
Beep
Exit Sub
End If
Next i
End If
ListBox2.AddItem ListBox1.Value
End Sub



Private Sub OKButton_Click()
Dim i As Integer
Dim col As Integer
Dim iLastRow As Integer
Dim Rng As Range

MsgBox "The 'To list' contains " & ListBox2.ListCount & " items."
For i = 0 To ListBox2.ListCount - 1
MsgBox ListBox2.List(i)

col = Application.Match(ListBox2.List(i),
Range(Userrange.Address), 0)
iLastRow = Cells(Rows.Count, col).End(xlUp).row
Set Rng = Range(Cells(AccountOnRow, col), Cells(iLastRow, col))

ActiveWorkbook.Names.Add Name:="VBA" & (i), RefersTo:=Rng
Next i
Unload Me
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default ListBox2.AddItem ListBox1.Value becomes a String when being Integer?

Everything in a listbox is a string. Just convert it to a number to perform
your match

Application.Match(clng(ListBox2.List(i)), Range(Userrange.Address),0)

Note that sample code may contain syntax errors not introduced by me.

--
Regards,
Tom Ogilvy



"SIGE" wrote in message
om...
Hi Bob, Tom, ...all other Helping Hands,

I am reading in values (integers & strings) in listbox1 as follows:
UserForm1.ListBox1.AddItem Sheets("Sheet1").Cells(Userrange.row,
kolom)

I make a selection out of Listbox1 into Listbox2 as in sub:
AddButton_Click()

===Does my Integer gets converted into String with:
ListBox2.AddItem ListBox1.Value ????

and therefore cannot find the Integer in the
"Application.Match(ListBox2.List(i), Range(Userrange.Address),
0)"-function?!

How to get the same cell "formats" in listbox2 as in listbox1?
Sige


Private Sub AddButton_Click()
Dim i As Integer
If ListBox1.ListIndex = -1 Then Exit Sub
If Not cbDuplicates Then
' See if item already exists
For i = 0 To ListBox2.ListCount - 1
If ListBox1.Value = ListBox2.List(i) Then
Beep
Exit Sub
End If
Next i
End If
ListBox2.AddItem ListBox1.Value
End Sub



Private Sub OKButton_Click()
Dim i As Integer
Dim col As Integer
Dim iLastRow As Integer
Dim Rng As Range

MsgBox "The 'To list' contains " & ListBox2.ListCount & " items."
For i = 0 To ListBox2.ListCount - 1
MsgBox ListBox2.List(i)

col = Application.Match(ListBox2.List(i),
Range(Userrange.Address), 0)
iLastRow = Cells(Rows.Count, col).End(xlUp).row
Set Rng = Range(Cells(AccountOnRow, col), Cells(iLastRow, col))

ActiveWorkbook.Names.Add Name:="VBA" & (i), RefersTo:=Rng
Next i
Unload Me
End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 44
Default ListBox2.AddItem ListBox1.Value becomes a String when being Integer?


Hi Tom,

Thanks!!!
A subtle piece of art!
:o)))
Sige

"NOSPAM" to be removed for direct mailing...

*** Sent via Developersdex http://www.developersdex.com ***
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
Help with: ListBox1.AddItem (ws.Name) Ron de Bruin Excel Worksheet Functions 0 May 18th 05 07:02 PM
Listbox1 to Listbox2? Moretakitty Excel Programming 16 January 20th 05 10:25 PM
Userform - Populate Listbox2 based on selection in Listbox1 miker1999[_16_] Excel Programming 0 April 29th 04 04:38 AM
listbox1.additem syntax for multiple columns Russ Robelen Excel Programming 4 December 31st 03 09:01 PM
(Worksheet)Listbox1.additem = (Form)Listbox1.value ?? Tom Ogilvy Excel Programming 0 September 2nd 03 07:36 PM


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