K
Keith R
I'm writing some code to pull ranges from different data worksheets (always
one row, column C to AM) into an array, validate the data (make sure only
integers are present), do some calculations on the data (simple division),
put the results in a new array (two dimensional), then drop the contents of
that new array into a new target range.
When I pull the data in, I need to validate it to make sure that everything
that is pulled in is an integer (or blank). I'm wondering what syntax I
could use to cycle through an array in VBA, similar to:
For each (object) in (collection). What is the "name" of the object of one
"bucket" in an array?
I'm also having trouble with the syntax to pull the range into the array,
if anyone wants to give me a syntax hint there
is it because I'm declaring the size of the array, rather than an open
variant? If I did use a variant, can I treat it like an array without
cycling through anyway to dump it into an array? (I've tried dimming the
array as 2 dimensional as well, e.g. (1 to 1, 1 to 38) and that didn't seem
to work either)
Thanks,
Keith
XL97
Snippet:
Dim TArray(1 To 38) ' to hold my values from column C to AM
For RVal = 1 To 5 ' row number to pull the range from
UseRange = "C" & Trim(Str(RVal)) & ":AM" & Trim(Str(RVal))
' next line has had many tweaks, but still not working
TArray = ActiveSheet.Range(UseRange).Value
' I want to insert better syntax here, vs:
For i = 1 to 38
if isnumeric(TArray(i).value) then
if mod(TArray(i).value,1)=0 then
'do stuff
end if
end if
Next
Next
one row, column C to AM) into an array, validate the data (make sure only
integers are present), do some calculations on the data (simple division),
put the results in a new array (two dimensional), then drop the contents of
that new array into a new target range.
When I pull the data in, I need to validate it to make sure that everything
that is pulled in is an integer (or blank). I'm wondering what syntax I
could use to cycle through an array in VBA, similar to:
For each (object) in (collection). What is the "name" of the object of one
"bucket" in an array?
I'm also having trouble with the syntax to pull the range into the array,
if anyone wants to give me a syntax hint there
is it because I'm declaring the size of the array, rather than an open
variant? If I did use a variant, can I treat it like an array without
cycling through anyway to dump it into an array? (I've tried dimming the
array as 2 dimensional as well, e.g. (1 to 1, 1 to 38) and that didn't seem
to work either)
Thanks,
Keith
XL97
Snippet:
Dim TArray(1 To 38) ' to hold my values from column C to AM
For RVal = 1 To 5 ' row number to pull the range from
UseRange = "C" & Trim(Str(RVal)) & ":AM" & Trim(Str(RVal))
' next line has had many tweaks, but still not working
TArray = ActiveSheet.Range(UseRange).Value
' I want to insert better syntax here, vs:
For i = 1 to 38
if isnumeric(TArray(i).value) then
if mod(TArray(i).value,1)=0 then
'do stuff
end if
end if
Next
Next