ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Help with listboxes (https://www.excelbanter.com/excel-programming/433572-help-listboxes.html)

TotallyConfused

Help with listboxes
 
I need help with the following: Below is what I have for my list boxes. I
have three list boxes in a tab control page in my Userform. This is fine.
However, I need to have the column heads show in my listboxes. I was told to
use "RowSource" in the properties. However, when I enter "A2:F27" in the
"RowSource", I get Run Time Error 70. I have review the forum for answers
and my understanding is that you can only use code or "RowSource" for range.
How than can I get my column heads to show in the list box??? Thank you in
advance for any information you can provide.


Private Sub UserForm_Initialize()
Me.txtFormDate = Date
'Me.FormDate = format(date,"mm-dd-yyyy")
Me.ListBox2.List = Sheet7.Range("A2:F27").Value
Me.ListBox3.List = Sheet1.Range("A2:G78").Value
Me.ListBox4.List = Sheet6.Range("A2:B300").Value

Patrick Molloy[_2_]

Help with listboxes
 
Option Explicit
Private Sub UserForm_Initialize()
SetLinks
End Sub
Sub SetLinks()
With ListBox1
.ColumnCount = 6
.RowSource = "Sheet1!A1:F7"
.ColumnHeads = True
End With
End Sub


"TotallyConfused" wrote:

I need help with the following: Below is what I have for my list boxes. I
have three list boxes in a tab control page in my Userform. This is fine.
However, I need to have the column heads show in my listboxes. I was told to
use "RowSource" in the properties. However, when I enter "A2:F27" in the
"RowSource", I get Run Time Error 70. I have review the forum for answers
and my understanding is that you can only use code or "RowSource" for range.
How than can I get my column heads to show in the list box??? Thank you in
advance for any information you can provide.


Private Sub UserForm_Initialize()
Me.txtFormDate = Date
'Me.FormDate = format(date,"mm-dd-yyyy")
Me.ListBox2.List = Sheet7.Range("A2:F27").Value
Me.ListBox3.List = Sheet1.Range("A2:G78").Value
Me.ListBox4.List = Sheet6.Range("A2:B300").Value


TotallyConfused

Help with listboxes
 
Thank you Patrick for responding. I have included your response to the code
and the "Private Sub UserForm_Initialize()
SetLinks" Gives me and "Ambiguous message"

If I take off "Priviate Sub UserForm_Initialize()
SetLinks
End Sub

I can view my UserForm but no column heads. Can you please tell me what I
am doing wrong? Thank you


"Patrick Molloy" wrote:

Option Explicit
Private Sub UserForm_Initialize()
SetLinks
End Sub
Sub SetLinks()
With ListBox1
.ColumnCount = 6
.RowSource = "Sheet1!A1:F7"
.ColumnHeads = True
End With
End Sub


"TotallyConfused" wrote:

I need help with the following: Below is what I have for my list boxes. I
have three list boxes in a tab control page in my Userform. This is fine.
However, I need to have the column heads show in my listboxes. I was told to
use "RowSource" in the properties. However, when I enter "A2:F27" in the
"RowSource", I get Run Time Error 70. I have review the forum for answers
and my understanding is that you can only use code or "RowSource" for range.
How than can I get my column heads to show in the list box??? Thank you in
advance for any information you can provide.


Private Sub UserForm_Initialize()
Me.txtFormDate = Date
'Me.FormDate = format(date,"mm-dd-yyyy")
Me.ListBox2.List = Sheet7.Range("A2:F27").Value
Me.ListBox3.List = Sheet1.Range("A2:G78").Value
Me.ListBox4.List = Sheet6.Range("A2:B300").Value


Patrick Molloy[_2_]

Help with listboxes
 
either use code you set the listbox properties (as I did), or set them
yourself using the properties window.

if you already have an Initialise, just add the call to SetLinks to it

"TotallyConfused" wrote:

Thank you Patrick for responding. I have included your response to the code
and the "Private Sub UserForm_Initialize()
SetLinks" Gives me and "Ambiguous message"

If I take off "Priviate Sub UserForm_Initialize()
SetLinks
End Sub

I can view my UserForm but no column heads. Can you please tell me what I
am doing wrong? Thank you


"Patrick Molloy" wrote:

Option Explicit
Private Sub UserForm_Initialize()
SetLinks
End Sub
Sub SetLinks()
With ListBox1
.ColumnCount = 6
.RowSource = "Sheet1!A1:F7"
.ColumnHeads = True
End With
End Sub


"TotallyConfused" wrote:

I need help with the following: Below is what I have for my list boxes. I
have three list boxes in a tab control page in my Userform. This is fine.
However, I need to have the column heads show in my listboxes. I was told to
use "RowSource" in the properties. However, when I enter "A2:F27" in the
"RowSource", I get Run Time Error 70. I have review the forum for answers
and my understanding is that you can only use code or "RowSource" for range.
How than can I get my column heads to show in the list box??? Thank you in
advance for any information you can provide.


Private Sub UserForm_Initialize()
Me.txtFormDate = Date
'Me.FormDate = format(date,"mm-dd-yyyy")
Me.ListBox2.List = Sheet7.Range("A2:F27").Value
Me.ListBox3.List = Sheet1.Range("A2:G78").Value
Me.ListBox4.List = Sheet6.Range("A2:B300").Value



All times are GMT +1. The time now is 02:12 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com