473,399 Members | 3,919 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Finding the size of a variant

Paul Johnson
Hi,

I've got most of the code in my VBA running (which is a miracle given it's the first time I've attempted anything in VBA), but I've hit a snag.

I am reading in a variable number of rows by like this

Expand|Select|Wrap|Line Numbers
  1. dim cells() as variant
  2. for module = 0 to 9
  3.     for student = 2 to 35
  4.         if module < 3 then
  5.             s = nd1sc(module) + student
  6.             e = nd1ec(module) + student
  7.             inuse = nd1compulsory
  8.         else
  9.             s = nd1se(module - 3) + student
  10.             e = nd1ee(module - 3) + student
  11.             inuse = nd1elective
  12.         endif
  13.     redim cells() as variant
  14.     cells = inuse.getCellRangeByName(s & ":" & e)
  15.     for checked = 0 to ubound(cells) ' dies here
  16.         if cells(checked) = "P" then pass = pass + 1
  17.     next checked
  18.  
nd1compulsory / elective are just two workbooks in my spreadsheet

The code will compile, but when I run the code, it dies saying that the array has to be dimensioned.

As the number of cells being read in are variable, is there a way to find the size of the number of cells read in?

The idea of the spreadsheet is so I can keep of the overall marks for my students starting in September.

Thanks

Paul
Aug 16 '11 #1
1 5117
NeoPa
32,556 Expert Mod 16PB
Paul,

You ReDim the Cells array, but you never specify any dimensions so UBound has nothing to work from (hence the error).

Cells is also a used word in Excel, so it's strongly advisable to avoid using it for something else. It's only likely to confuse you.

As a last comment, let me direct you towards some sensible instructions on how best to approach using and posting code on here (When Posting (VBA or SQL) Code).
Aug 16 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: cr88192 | last post by:
for various reasons, I added an imo ugly hack to my xml parser. basically, I wanted the ability to have binary payload within the xml parse trees. this was partly because I came up with a binary...
2
by: Stewart Allen | last post by:
Hi There I have a function that does some calculations depending on the 2 date arguments passed into it: Function GetPeriods(dteStart As Date, dteEnd As Date) As Integer The function has 2...
79
by: syntax | last post by:
what is the size of a pointer? suppose i am writing, datatype *ptr; sizeof(ptr); now what does this sizeof(ptr) will give? will it give the size of the
9
by: minil | last post by:
Hi any c function in linux to return size of directory (Including its files & subdirectories & its files).. I can stat() only files . not for directories. please reply me soon Thanks in...
2
by: yxq | last post by:
Hello I want to get Windows clipboard data size, seem to use the function "GetClipboardDataSize". Could anyone please tell how to do using vb.net? Thanks
7
by: Daniel Kaplan | last post by:
I have the item below at the top of my style sheet. And it seems that the font-szie is ignored. I know that my linked style sheet is being read, and used because if I remove the font-family line,...
0
by: .::alex::. | last post by:
Hello, Maybe you already guess the problem. I have a COM with a method in a Interface like that: HRESULT GetArray(VARIANT *pVal); so this method will return a VARIANT. This VARIANT contains...
5
by: vml | last post by:
I have a python com object which contains a method to inverse an array in vb 6 the definition of the class is : class Fop: _public_methods_ = def SqVal(self,*val): #vol=(val,val)...
3
by: samerendra | last post by:
Hi all plz gives the exat query for finding size of database Thanks Samerendra Singh
2
by: Josiah Vergonio | last post by:
#include<iostream> using namespace std; class Test { public: void search(int arr) { int count=0; int size=(sizeof arr/sizeof arr); cout << "In search function, size = " <<size<<endl;
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.