|
-
Nov 10th, 2011, 02:28 PM
#1
Thread Starter
New Member
[RESOLVED] VBA Excel 2007: Dynamic Arrays
Hey everyone,
I am working on a code that will add a cell that contains the word "Total" to an array and skip everything else. I could conceivably just delete the rows of everything that doesn't contain "Total" and create an array that way but I am trying to avoid deleting data. This code works sometimes and others it does not. Any sight would be very much appreciated. Thanks!!!!!!! 
Code:
Sub companyarray()
Dim myarray() As String
Dim index As Integer
Dim xrow As Integer
Dim size As Integer
xrow = 2
size = 1
index = 0
ReDim myarray(size)
Sheets("Pivot Information").Select
Range("F3").Select
''''''FILL ARRAY
Do Until Cells(xrow, 6).Value = ""
If ActiveCell.Value Like "*Total*" Then
Cells(xrow, 6).Select
myarray(index) = Cells(xrow, 6).Value
size = size + 1
ReDim Preserve myarray(size)
index = index + 1
xrow = xrow + 1
Else:
xrow = xrow + 1
ActiveCell.Offset(1).Select
End If
Loop
-
Nov 10th, 2011, 02:52 PM
#2
Re: VBA Excel 2007: Dynamic Arrays
avoid using select, selection, activate or active anything
try like
vb Code:
index = 0 redim myarray(index) with Sheets("Pivot Information") ''''''FILL ARRAY Do Until .Cells(xrow, 6).Value = "" If .cells(xrow, 6).Value Like "*Total*" Then myarray(index) = .Cells(xrow, 6).Value index = index + 1 ReDim Preserve myarray(index) End If xrow = xrow +1 Loop end with
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|