ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   User defined type not defined (https://www.excelbanter.com/excel-programming/342774-user-defined-type-not-defined.html)

Blur

User defined type not defined
 

I keep getting user defined type not defined when i try to run this...
Which are the neccessary libraries which i have to add in my
references? I have added the Microsoft VB Extensibility but it does not
work.. It always break at
" Set TempDO = New DataObject "

It's supposed to place my 15 randomly selected cells on the
clipboard... how can i modify it to place the results on the worksheet
itself?
Many thanks.....



Code:
--------------------
Sub GetRandom()
Dim iRows As Integer
Dim iCols As Integer
Dim iBegRow As Integer
Dim iBegCol As Integer
Dim J As Integer
Dim sCells As String

Set TempDO = New DataObject

iRows = Selection.Rows.Count
iCols = Selection.Columns.Count
iBegRow = Selection.Row
iBegCol = Selection.Column

If iRows < 16 Or iCols 1 Then
MsgBox "Too few rows or too many columns"
Else
Randomize Timer
sCells = ""
For J = 1 To 15
iWantRow = Int(Rnd() * iRows) + iBegRow
sCells = sCells & Cells(iWantRow, iBegCol) & vbCrLf
Next J
TempDO.SetText sCells
TempDO.PutInClipboard
End If
End Sub
--------------------


--
Blur
------------------------------------------------------------------------
Blur's Profile: http://www.excelforum.com/member.php...o&userid=28096
View this thread: http://www.excelforum.com/showthread...hreadid=476058


Dave Peterson

User defined type not defined
 
You'll want to add a reference (Tools|references in the VBE) to:
Microsoft Forms 2.0 Object library

So that your project knows what a Dataobject is.

Also, I'd add one more dim statement:

Dim TempDO As MSForms.DataObject



Blur wrote:

I keep getting user defined type not defined when i try to run this...
Which are the neccessary libraries which i have to add in my
references? I have added the Microsoft VB Extensibility but it does not
work.. It always break at
" Set TempDO = New DataObject "

It's supposed to place my 15 randomly selected cells on the
clipboard... how can i modify it to place the results on the worksheet
itself?
Many thanks.....

Code:
--------------------
Sub GetRandom()
Dim iRows As Integer
Dim iCols As Integer
Dim iBegRow As Integer
Dim iBegCol As Integer
Dim J As Integer
Dim sCells As String

Set TempDO = New DataObject

iRows = Selection.Rows.Count
iCols = Selection.Columns.Count
iBegRow = Selection.Row
iBegCol = Selection.Column

If iRows < 16 Or iCols 1 Then
MsgBox "Too few rows or too many columns"
Else
Randomize Timer
sCells = ""
For J = 1 To 15
iWantRow = Int(Rnd() * iRows) + iBegRow
sCells = sCells & Cells(iWantRow, iBegCol) & vbCrLf
Next J
TempDO.SetText sCells
TempDO.PutInClipboard
End If
End Sub
--------------------

--
Blur
------------------------------------------------------------------------
Blur's Profile: http://www.excelforum.com/member.php...o&userid=28096
View this thread: http://www.excelforum.com/showthread...hreadid=476058


--

Dave Peterson


All times are GMT +1. The time now is 12:41 PM.

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