INSERTING A BLANK ROW BETWEEN LISTBOX ROWS

chazrab

Well-known Member
Joined
Oct 21, 2006
Messages
917
Office Version
  1. 365
Platform
  1. Windows
How would I insert a blank row between listbox rows when displaying the data.
I did this with a textbox but the same code generates an invalid property value
at the beginning. Best explained with images below and the following code
Code:
Private Sub ListBox1_Click()
Dim n As Long
n = ListBox1.ListIndex
TextBox1.Value = ListBox1.List(n, 1) _
& vbCrLf _
& vbCrLf _
& ListBox1.List(n + 1, 1) _
& vbCrLf + ListBox1.List(n + 2, 1) _
& vbCrLf _
& vbCrLf + ListBox1.List(n + 3, 1) _
& vbCrLf + ListBox1.List(n + 4, 1) _
& vbCrLf _
& vbCrLf + ListBox1.List(n + 5, 1) _
& vbCrLf + ListBox1.List(n + 6, 1) _
& vbCrLf _
& vbCrLf + ListBox1.List(n + 7, 1) _
& vbCrLf + ListBox1.List(n + 8, 1) _
& vbCrLf _
& vbCrLf + ListBox1.List(n + 9, 1) _
& vbCrLf + ListBox1.List(n + 10, 1) _
& vbCrLf

The vbCrLf carriage return line feed easily enough inserts a space - in a textbox. And

How would I do this same thing, achieve the same blank row but with Listbox1 ? I

I thought images below with the code above that works well - with a TEXTBOX would explain clearly.

The problem is, a textbox has limited functionality. More can be accomplished in this app using a listbox.

Apologies for long post. Thanks very much for anyone's help.

cr
 

Attachments

  • TEXTBOX WITH SPACES .jpg
    TEXTBOX WITH SPACES .jpg
    110.5 KB · Views: 12
  • LISTBOX WITH NO SPACES OR BLANK ROWS.jpg
    LISTBOX WITH NO SPACES OR BLANK ROWS.jpg
    141.8 KB · Views: 11
  • ERROR GENERATED AT THIS LINE REPLACING TEXTBOX1 WITH LISTBOX1.jpg
    ERROR GENERATED AT THIS LINE REPLACING TEXTBOX1 WITH LISTBOX1.jpg
    79.2 KB · Views: 11
  • ERROR GENERATED AT LISTBOX1.VALUE =LISTBOX1.LIST(n,1) _ LINW.jpg
    ERROR GENERATED AT LISTBOX1.VALUE =LISTBOX1.LIST(n,1) _ LINW.jpg
    81.5 KB · Views: 12

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
this is done in 3 lines, but you can combine everything in 1 line, but that 'll be less readable
VBA Code:
     With ComboBox1                                             'your combobox, textbox, ...
          arr = Application.Transpose(.List)                    'read the list of the 1st combobox in an array
          s = Join(arr, "||")                                   'make a string and add 2 pipes as separator
          b = Split(s, "|")                                     'split on that pipe
          ComboBox2.List = b                                    'apply to a(nother) combobox, listbox, ...
     End With
 
Upvote 0
HI BSALV -
I just read your code but have not tested yet because your code refers to
a Combobox1(With ComboBox1). I'm working with a Listbox(Listbox1) if that
makes any difference. I'll replace Combobox1 with 'Listbox1' in your code above
and put this in the userform's initialize event as soon as I get through typing this.

I'm excited because of the simplicity of your code, and, if it will insert a blank row
between Listbox1 rows instead of these cumbersome carriage line feeds I used.

Please get back to me if I'm reading this incorrectly.

Thanks for all your help.
cr
 
Upvote 0
that should work, it just did something similar in a userform of mine
VBA Code:
Private Sub UserForm_Initialize()
     c_01.List = Sheets("kladblad").ListObjects(1).DataBodyRange.Columns(2).Value     'add data to 1st listbox

     c_01.List = a
     arr = Application.Transpose(c_01.List)                     'read the list of the 1st combobox in an array
     s = Join(arr, "||")                                        'make a string and add 2 pipes as separator
     b = Split(s, "|")                                          'split on that pipe
     CB_Add.List = b                                            'apply to a(nother) combobox, listbox, ...
     '
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top