Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 10th, 2007, 12:46 PM
Registered User
 
Join Date: Sep 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Help: How to pass a cell matrix as a variable in t


I need to pass a cell matrix with variable size (m X n) to a own defined VBA fuction myfun(dataRange as Range). In this function the selected cell matrix will be stored in an data array. I used to use Range.CurrentArray or Range.Value2 to store the data into an assigned array variable successfully. However, it requires the cells contain no formula. If the data in the cells are obtained by a formula, everything screws up.

The code is shown below:

‘The function stores the data in selected cell matrix (for example: A2:D8, but the cell matrix could be any size and at any location), and to retrieve the total column and row numbers.

Function myfun(dataRange as Range) as Variant()

Dim Columns as Integer, Rows as Integer
myfun=dataRange.CurrentArray
‘myfun=dataRange.Value2
If IsArray(myfun)=True then
Columns=UBound(myfun,1)-LBound(myfun,1)
Rows=UBound(myfun,2)-LBound(myfun,2)
Else
Columns=1
Rows=1
End If

End Function


BTW: if all the data in selected cell matrix are double, how can I pass this matrix to a double variable? So far I have to define the array as Variant.







Similar Threads
Thread Thread Starter Forum Replies Last Post
variable used as cell reference? dabith Excel VBA 3 March 8th, 2014 12:53 AM
Using a variable to reference a cell MikeCt203 Excel VBA 2 March 24th, 2008 04:02 PM
pass java variable to xsl variable kathy1016cats XSLT 1 June 14th, 2006 06:23 PM
pass variable kapi.goel C# 1 January 6th, 2006 05:54 AM
Passing the cell reference to a variable Artist Excel VBA 0 April 14th, 2004 04:34 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.