I have a table like this
Now I want to display this table In the userform. How to display it in the userform. I'm thinking of selecting the entire table range and displaying it as a label, because I want the table TO BE UNEDITABLE. How to do this?. I want to write a VBA code. please help me with this.
I have tried another way as well like displaying it in a listbox, but the I couldn't get the correct output.
The vba script which I added to the userform is:
Private Sub UserForm_Initialize()
ListBox1.List = Sheets("Overview").Range("C1:H3").CurrentRegion.Value
End Sub
when I used the above code, the output I got is
I'm not getting the entire table in the listbox . what's the error I'm doing??
you can use the simillar code:
LastColumn = Sheets("XY").Cells(1, Columns.Count).End(xlToLeft).Column
Here's another, more involved option to insert your table as an image into your UserForm:
Step 1
Add the following code to your UserForm:
Note: Change "Sheet1" to your sheet name and "TestTable" to your table name. You can also change "MyBitmap.bmp" to any file name that you would like.
Step 2
Add a module with the following code adapted from answer #6 here:
Your table will be inserted as an image into your UserForm. You can change the size of the image as necessary to fit your needs.
Note - This saves the image to the folder where the workbook is saved. It then deletes the image file when the UserForm is closed. If you want the user to select where to save the image, replace this line:
With this line:
You'll probably want to make some other changes to the code then as well.
You have two questions here.
Firstly, you can populate userform Labels with your data which will be uneditable. Note that you need to set the
Caption
property for the userform and label display contents. Some basic code, which should be placed in the userform module, is shown below to get you going.Secondly, if you still want to use a ListBox (using VBA) then have a look at the
AddItem
method (an example here) and develop the following starter code for multi-columns.