Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Iteratively removing data from a VBA array

I initially wanted to be able to truncate an array as needed by the
code. An answer along with the initial code was found in a GoogleGroup.


When though an array that has stored numeric values is truncated, the
nature of the data stored is changed. For example, the values of the
array prior to truncation would be plain numbers e.g. 1, 2, 3 etc
whereas after running the truncation section, the remaining values
change into "1", "2", "3", etc.

I have attempted to convert to an Integer value but as shown below, it
was ineffective. Comparisons of data derived from the array with
distinctly defined numbers numbers are possible. Comparisons with
variables to which values have been pre-assigned are unfortunately not
possible.

As this does not allow any further array manipulation & valid data
extraction, I have reached a standstill and would appreciate any
suggestions anyone would have to offer.

Many thanks

Kostas

PS. VBA code example of array truncation as follows :



Sub Array_truncation()


vv = Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)


var1 = 2

Debug.Print ""
Debug.Print "New Run"

For Each x In vv
Debug.Print x

Next x

If vv(2) = var1 Then Debug.Print "2=2 ok" Else Debug.Print "problem at
stage 1"

Debug.Print (2)
Dim Unique
Unique = Chr(255)


' This example is "Zero" based, so index is 4 & 8
vv(4) = Unique

'Now, delete them...
vv = Filter(vv, Unique, False)

Debug.Print ""

For Each x In vv

Debug.Print x

Next x

If vv(2) = var1 Then Debug.Print "2=2 ok" Else Debug.Print "problem at
stage 2"


vv(4) = Unique

'Now, delete them...
vv = Filter(vv, Unique, False)

Debug.Print ""

Dim x2 As Integer


For Each x In vv
x = x2
Debug.Print x

Next x

If vv(2) = var1 Then Debug.Print "2=2 ok" Else Debug.Print "problem at
stage 3"



End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Iteratively removing data from a VBA array

Look at the help on the Filter function. It works on an array of strings, so
your values are converted to strings when you use the filter function.

Your problem on stage 3 is you set all your array values to the integer 0
and then compare them, i.e. element vv(2) (now zero) you compare it to
the number 2 and naturally that fails.

here is the output modified to show the type of the value:

New Run
0 Integer
1 Integer
2 Integer
3 Integer
4 Integer
5 Integer
6 Integer
7 Integer
8 Integer
9 Integer
2=2 ok
2

0 String
1 String
2 String
3 String
5 String
6 String
7 String
8 String
9 String
problem at stage 2

0 Integer
0 Integer
0 Integer
0 Integer
0 Integer
0 Integer
0 Integer
0 Integer
problem at stage 3

Not sure your problem is any more serious than not understanding that filter
works with strings.

--
Regards,
Tom Ogilvy


"Kostas" wrote:

I initially wanted to be able to truncate an array as needed by the
code. An answer along with the initial code was found in a GoogleGroup.


When though an array that has stored numeric values is truncated, the
nature of the data stored is changed. For example, the values of the
array prior to truncation would be plain numbers e.g. 1, 2, 3 etc
whereas after running the truncation section, the remaining values
change into "1", "2", "3", etc.

I have attempted to convert to an Integer value but as shown below, it
was ineffective. Comparisons of data derived from the array with
distinctly defined numbers numbers are possible. Comparisons with
variables to which values have been pre-assigned are unfortunately not
possible.

As this does not allow any further array manipulation & valid data
extraction, I have reached a standstill and would appreciate any
suggestions anyone would have to offer.

Many thanks

Kostas

PS. VBA code example of array truncation as follows :



Sub Array_truncation()


vv = Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)


var1 = 2

Debug.Print ""
Debug.Print "New Run"

For Each x In vv
Debug.Print x

Next x

If vv(2) = var1 Then Debug.Print "2=2 ok" Else Debug.Print "problem at
stage 1"

Debug.Print (2)
Dim Unique
Unique = Chr(255)


' This example is "Zero" based, so index is 4 & 8
vv(4) = Unique

'Now, delete them...
vv = Filter(vv, Unique, False)

Debug.Print ""

For Each x In vv

Debug.Print x

Next x

If vv(2) = var1 Then Debug.Print "2=2 ok" Else Debug.Print "problem at
stage 2"


vv(4) = Unique

'Now, delete them...
vv = Filter(vv, Unique, False)

Debug.Print ""

Dim x2 As Integer


For Each x In vv
x = x2
Debug.Print x

Next x

If vv(2) = var1 Then Debug.Print "2=2 ok" Else Debug.Print "problem at
stage 3"



End Sub


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Iteratively removing data from a VBA array

The problem is that the filter function produces a string based array.
Therefore, Once any array has been filtered it is converted from
numeric to string-based.

I believe that the easiest way around my problem would be to re-convert
the truncated array from string based to numeric-based array, every
time it is truncated. Unfortunately though, I have been unable to track
down the code that would allow me to do that.

Any help appreciated

Many thanks

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
removing a cell from an array Desperate Excel Discussion (Misc queries) 2 October 19th 08 08:31 AM
Removing Data Tables formed from importing data from Access Andrea Jones Excel Discussion (Misc queries) 0 April 10th 08 12:01 PM
Global array data got erased after removing reference in VBA Santh Excel Programming 1 February 7th 06 12:56 PM
removing blank entries from an array TheIrishThug[_5_] Excel Programming 2 December 19th 05 09:34 PM
Scanning for Duplicate Data in a Column, Merging Data and Finally Removing All Duplicates...? : VB : Excel Programming 2 August 24th 03 02:22 PM


All times are GMT +1. The time now is 01:59 PM.

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

About Us

"It's about Microsoft Excel"