Spreadsheet Control on a Userform

azref
06-26-2010, 05:33 PM
I am using an excel userform to enter employee information into a worksheet. On this form I have a button that will hide the current form then open a second userform which will display information from the worksheet into a spreadsheet control on the second userform. The problem is that I can’t find a way to get the data from the worksheet to paste into the spreadsheet on the second userform.

Everything I have tried results in - Run-time error ‘91”: Object variable or With block variable not set.

It seems that vb does not recognize this as a spreadsheet. What do I need to do to be able to insert the data from the worksheet?

JSTKwan
06-28-2010, 08:15 AM
I've extracted out the code that I used to load the SS control, just alter to to suit your needs:

Sub LoadSpreadSheetControl()
Dim lRow As Long
Dim lColumn As Long
Dim WS As Excel.Worksheet
Dim LastColumnLetter As String

LastRow = FindLastRow("A")
Set WS = Sheet3
LastColumn = Cells(1, Columns.Count).End(xlToLeft).Column
LastColumnLetter = ColumnLetter(LastColumn)

With Spreadsheet1
.Range("A1:" & LastColumnLetter & LastRow) = _
WS.Range("A1:" & LastColumnLetter & LastRow).Value
End With
Set WS = Nothing
End Sub

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum