In Excel I'm looping through some data in a sheet called "temp" and checking if any cell is red (this indicates an error).
Before this code below, I take my data (2 columns of data, 8 rows long) in Sheet "temp" through a test and assign passed data as green, ie: RGB(0, 200, 0). Then I want to verify that all 8 rows passed in another sheet called "main":
dim errorz(0) as variant
dim errorz_string as string
for i = 1 to 8
if sheets("temp").cells(i, 2).interior.color <> RGB(0, 200, 0) then
sheets("temp").cells(i, 3) = "Not verified"
sheets("temp").cells(i, 3).interior.color = RGB(200, 0, 0)
redim preserve errorz( UBound(errorz)-LBound(errorz) + 1 )
errorz( UBound(errorz)-LBound(errorz) ) = sheets("temp").cells(i, 1)
end if
next i
if UBound(errorz) - LBound(errorz) = 0 then
sheets("main").cells(1,1) = "Yes all 8 in temp verified."
end if
if UBound(errorz) - LBound(errorz) <> 0 then
for j = LBound(info.errorz) to UBound(info.errorz)
info.errorz(j) = "'" & info.errorz(j) & "'"
next j
errorz_string = Join(info.errorz, ",")
sheets("main").cells(1,1) = "No, missing " & errorz_string & " in temp"
end if
redim errorz(0)
errorz_string = ""
I've never used arrays before and am confused about redefining an array to be empty and length 0, and then increasing the length to 1 in a loop. For example, does redim errorz(0) create an empty array of length 0?
Also, initially when this array is of length 0, would "UBound(errorz)-LBound(errorz)" return 0 or 1 or an error?
redim errorz(0)will clearerrorzand set the upper bound to zero, so it will be the same aserrorz(0 to 0)Subtracting the lower from the upper bound would give you zero. Assuming you're not usingOption Base 1(which I think is a bad idea anyhow).main. Also, what isinfo.errorzsupposed to be?