-
Dec 11th, 2020, 09:53 AM
#1
Thread Starter
New Member
[RESOLVED] List box
Hello, i have problem , when ever i try to add info from cells to list box it also adds empty spaces, how could i change this?
Here is my code
Code:
Private Sub CommandButton1_Click()
ListBox1.Clear
If TypeOf Selection Is Range Then
For i = 1 To Selection.Rows.Count
For j = 1 To Selection.Columns.Count
ListBox1.AddItem (Selection.Cells(i, j))
Next
Next
End If
End Sub
Last edited by dday9; Dec 11th, 2020 at 10:52 AM.
Reason: Added Code Tags
-
Dec 11th, 2020, 10:02 AM
#2
Re: List box
Are you sure that this is VB.NET? Looks more like VB6 or maybe VBA.
-
Dec 11th, 2020, 10:10 AM
#3
Thread Starter
New Member
Re: List box
Im not sure i know the difference. what forum would you suggest me?
-
Dec 11th, 2020, 10:21 AM
#4
Re: List box
I would suggest that you work out what language you're actually using and then post in the forum dedicated to that language.
-
Dec 11th, 2020, 10:57 AM
#5
Re: List box
What software application are you using to develop the code?
-
Dec 11th, 2020, 12:03 PM
#6
Thread Starter
New Member
-
Dec 11th, 2020, 12:05 PM
#7
Re: List box
Moved to office development which is for VBA questions.
-
Dec 12th, 2020, 02:14 AM
#8
Re: List box
try like
Code:
if not isempty(selection.celss(i, j)) then ListBox1.AddItem (Selection.Cells(i, j))
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Dec 12th, 2020, 04:13 AM
#9
Thread Starter
New Member
Re: List box
Okey, tnx, but how could i integrete in my code?
Do i make another ''if'' or i add it with ''and'' to the first one?
-
Dec 12th, 2020, 05:05 AM
#10
Re: List box
just swap it in place of the existing line to additems
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|