PC Review


Reply
Thread Tools Rate Thread

Array Issues… Please help me….

 
 
mju
Guest
Posts: n/a
 
      15th Apr 2010
I am having problems with my code. It used to work fine until today. I am
getting type mismatch error in f = Array("STY", "PK", "COLOR", "SZ", "ITEM",
"UP", "STORE")

What am I doing wrong!!

Sample Code

L = 0
L = ActiveCell.SpecialCells(xlLastCell).Row
Dim f() As String

f = Array("STY", "PK", "COLOR", "SZ", "ITEM", "UP", "STORE")
Dim FR(7) As Variant
Dim x As Integer
Dim y As Integer
For x = 10 To 37 ' cycles through columns 10 to 37
For y = 1 To 7 ' cycles through all 7 of the items in the "F" array
' Checks the header to see if it is looking at the particular item from the
"F" array.
' Then assigns whatever column number that item is in. e.g. if the STYLE is
in colume 23 then FR(1) = 23.
If CELLS(1, x) = f(y) Then FR(y) = CELLS(1, x).Column
Next y
Next x

Thanks

 
Reply With Quote
 
 
 
 
Rick Rothstein
Guest
Posts: n/a
 
      15th Apr 2010
I am assuming you do NOT have an Option Base 1 statement, so your arrays are
defaulted to being zero-based; hence, this line is wrong...

For y = 1 To 7

It should be this...

For y = 0 To 6

because the Array function will automatically produce a zero-based array.
Also, just so you know, this line...

Dim FR(7) As Variant

creates an array of 8 elements with index numbers of 0,1,2,3,4,5,6,7. If you
don't use Option Base 1, then you should probably change that statement to
this...

Dim FR(6) As Variant

--
Rick (MVP - Excel)



"mju" <(E-Mail Removed)> wrote in message
news:1752C9B6-33B9-49F7-B8F0-(E-Mail Removed)...
> I am having problems with my code. It used to work fine until today. I am
> getting type mismatch error in f = Array("STY", "PK", "COLOR", "SZ",
> "ITEM",
> "UP", "STORE")
>
> What am I doing wrong!!
>
> Sample Code
>
> L = 0
> L = ActiveCell.SpecialCells(xlLastCell).Row
> Dim f() As String
>
> f = Array("STY", "PK", "COLOR", "SZ", "ITEM", "UP", "STORE")
> Dim FR(7) As Variant
> Dim x As Integer
> Dim y As Integer
> For x = 10 To 37 ' cycles through columns 10 to 37
> For y = 1 To 7 ' cycles through all 7 of the items in the "F" array
> ' Checks the header to see if it is looking at the particular item from
> the
> "F" array.
> ' Then assigns whatever column number that item is in. e.g. if the STYLE
> is
> in colume 23 then FR(1) = 23.
> If CELLS(1, x) = f(y) Then FR(y) = CELLS(1, x).Column
> Next y
> Next x
>
> Thanks
>

 
Reply With Quote
 
sali
Guest
Posts: n/a
 
      16th Apr 2010
"mju" <(E-Mail Removed)> je napisao u poruci interesnoj
grupi:1752C9B6-33B9-49F7-B8F0-(E-Mail Removed)...
>I am having problems with my code. It used to work fine until today. I am
> getting type mismatch error in f = Array("STY", "PK", "COLOR", "SZ",
> "ITEM",
> "UP", "STORE")


> Dim f() As String
>
> f = Array("STY", "PK", "COLOR", "SZ", "ITEM", "UP", "STORE")



is it type-writter mistake? 'f' should be declared as 'variant' to accept
'array' [but it is declared as 'string']


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Prevent cell/array references from changing when altering/moving thecell/array nme Microsoft Excel Misc 1 19th Sep 2008 01:53 PM
Redimming an array dynamically assigned from range (how to redim first dimension of a 2-D array? /or/ reverse the original array order) Keith R Microsoft Excel Programming 3 13th Nov 2007 04:08 PM
meaning of : IF(Switch; Average(array A, array B); array A) =?Utf-8?B?RFhBVA==?= Microsoft Excel Worksheet Functions 1 24th Oct 2006 06:11 PM
Pass from C# (framework 1.1) array of delegates to unmanaged DLL as array of function pointers verpeter@gmail.com Microsoft C# .NET 0 23rd Aug 2006 02:20 PM
select variables ranges, copy to array, paste the array in new workbook Mathew Microsoft Excel Worksheet Functions 1 1st Apr 2005 09:40 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:36 PM.