Question : Insert Range Contents into a UserForm

Is there a way to insert a range of a spreadsheet into a userform.??  What I would like to do is have a user click something and it will display the range("a1:f20") from sheet1 into a userform the way it's displayed on the sheet itself but in a userform.  Kinda like taking a picture of the sheet and then inserting that picture into the userform.

Thanks

Answer : Insert Range Contents into a UserForm

Thanks folderol,
I did it in Excel 2003 and it works fine, but it doesn't surprise me that you had to make those changes for it to work for you...seems like even same versions of Excel sometimes don't always act like it...

I had referenced only the Active sheet, and I did notice though, that you changed referencing the Active sheet to: Worksheets("Sheet1"), which is fine,  (which still doesn't make sense why you'de have to change that to make it work) but if you are going to reference a particular worksheet, you should probably do it through the entire related code, otherwise there is that chance of having information coming from 2 different sheets, and maybe not even knowing it...like if the user selected sheet 2 and run the code above, then it would still copy from sheet1, get the columns widths from sheet1, but get the number of columns to size from  sheet 2 (line 5)...you see what I mean I'm sure...and maybe you already knew all that anyway, or just overlooked that line with ActiveSheet in it...but it wouldn't be an issue anyway as long as Sheet1 was the only one ever selected when opening the form.

Anyway...I had to make an addition...forgot about row heights...so here is a file with that added.  I will post the code I used also...(it's still the same code that only references whatever sheet is active)

:-)
Albert
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
Private Sub CommandButton1_Click()
Dim n As Long
 
ActiveSheet.Range("A1:F20").Copy
Spreadsheet1.Range("A1").Paste
 
    For n = 1 To ActiveSheet.UsedRange.Columns.Count
        Spreadsheet1.Columns(n).ColumnWidth = ActiveSheet.Columns(n).ColumnWidth
    Next n
 
    For n = 1 To ActiveSheet.UsedRange.Rows.Count
        Spreadsheet1.Rows(n).RowHeight = ActiveSheet.Rows(n).RowHeight
    Next n
 
End Sub
 
Private Sub Spreadsheet1_SheetChange(ByVal Sh As OWC10.Worksheet, ByVal Target As OWC10.Range)
    ActiveSheet.Range(Spreadsheet1.ActiveCell.Address).Value = Spreadsheet1.ActiveCell.Value
End Sub
 
 
Random Solutions  
 
programming4us programming4us