Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 57
Default UDT copying a array to worksheet

I am trying to populate an array of an UDT and using it to copy it to a range
on a worksheet.

The last line in the code is a problem
Range("d1:f3").Value = myval ' <<<<<<<< it doesn't like myval

the error message displayed is
'Only user-defined types defined in public object modules can be coerced to
'or from a variant or passed to late-bound functions.

In the watch window myval(1) have the correct values

Private Type mymonths
mnum As Integer
mname As Variant
mday As Integer
End Type

Option Base 1

Public Sub getdate()

Dim x As mymonths
Dim myval(3) As mymonths

x.mnum = 1
x.mname = "Jan"
x.mday = 31
myval(1) = x

x.mnum = 2
x.mname = "Feb"
x.mday = 28
myval(2) = x

x.mnum = 3
x.mname = "Mar"
x.mday = 31
myval(3) = x

Set mthrng = Range("d1:f3")
With mthrng
.ClearContents
End With

Range("d1:f3").Value = myval


Any Help would be appreciated


Thanks
AH
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default UDT copying a array to worksheet

On Oct 24, 8:06 am, Allan wrote:
I am trying to populate an array of an UDT and using it to copy it to a range
on a worksheet.

The last line in the code is a problem
Range("d1:f3").Value = myval ' <<<<<<<< it doesn't like myval

the error message displayed is
'Only user-defined types defined in public object modules can be coerced to
'or from a variant or passed to late-bound functions.

In the watch window myval(1) have the correct values

Private Type mymonths
mnum As Integer
mname As Variant
mday As Integer
End Type

Option Base 1

Public Sub getdate()

Dim x As mymonths
Dim myval(3) As mymonths

x.mnum = 1
x.mname = "Jan"
x.mday = 31
myval(1) = x

x.mnum = 2
x.mname = "Feb"
x.mday = 28
myval(2) = x

x.mnum = 3
x.mname = "Mar"
x.mday = 31
myval(3) = x

Set mthrng = Range("d1:f3")
With mthrng
.ClearContents
End With

Range("d1:f3").Value = myval

Any Help would be appreciated

Thanks
AH


Hi Allan,

Replace Range("d1:f3").value = myval with the following:
Dim i As Integer

i = 1

Do Until i 3
Range("d" & i).Value = myval(i).mday
Range("e" & i).Value = myval(i).mname
Range("f" & i).Value = myval(i).mnum

i = i + 1
Loop


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 57
Default UDT copying a array to worksheet

Thanks for the speedy response, it works!!
AH


" wrote:

On Oct 24, 8:06 am, Allan wrote:
I am trying to populate an array of an UDT and using it to copy it to a range
on a worksheet.

The last line in the code is a problem
Range("d1:f3").Value = myval ' <<<<<<<< it doesn't like myval

the error message displayed is
'Only user-defined types defined in public object modules can be coerced to
'or from a variant or passed to late-bound functions.

In the watch window myval(1) have the correct values

Private Type mymonths
mnum As Integer
mname As Variant
mday As Integer
End Type

Option Base 1

Public Sub getdate()

Dim x As mymonths
Dim myval(3) As mymonths

x.mnum = 1
x.mname = "Jan"
x.mday = 31
myval(1) = x

x.mnum = 2
x.mname = "Feb"
x.mday = 28
myval(2) = x

x.mnum = 3
x.mname = "Mar"
x.mday = 31
myval(3) = x

Set mthrng = Range("d1:f3")
With mthrng
.ClearContents
End With

Range("d1:f3").Value = myval

Any Help would be appreciated

Thanks
AH


Hi Allan,

Replace Range("d1:f3").value = myval with the following:
Dim i As Integer

i = 1

Do Until i 3
Range("d" & i).Value = myval(i).mday
Range("e" & i).Value = myval(i).mname
Range("f" & i).Value = myval(i).mnum

i = i + 1
Loop



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copying an Array BDH Excel Worksheet Functions 0 February 21st 06 04:11 AM
Copying a Variant Array to a worksheet John Keith[_2_] Excel Programming 2 November 3rd 05 10:30 PM
Copying an Array Formula montagu Excel Discussion (Misc queries) 1 July 15th 05 07:30 PM
(Newbie) Copying values from an array to the worksheet Srdjan Kovacevic[_5_] Excel Programming 1 July 12th 05 03:47 PM
Copying an array to a worksheet: Excel 97 vs 2000 Trevor Shuttleworth Excel Programming 1 February 17th 04 03:11 AM


All times are GMT +1. The time now is 09:51 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"