vba - Returning Entire Array As String -
i have array populated if formula produces "x" in cell part of range:
private sub worksheet_change(byval target range) dim fault(10) boolean = 1 10 if range("a" & i).value = "x" fault(i) = true end if next msgbox fault 'vba errors here "type mismatch" end sub my question is, possible return entire array string. in above example, want message box return "0000000000" if there no faults. if there fault in 7th array, return "0000001000".
my aim check string equal "0000000000" in order proceed. however, if there's better way of checking if entire array false easier.
try this:
sub joinarray() dim fault(9) string, arrstring string = 1 10 if range("a" & i) = "x" fault(i - 1) = 1 else fault(i - 1) = 0 end if next arrstring = join(fault(), "") if instr(arrstring, "1") msgbox "fault found" else msgbox "no faults found" end if end sub notes:
- typically array 0 indexed
fault(9)allows 10 slots e.g. range("a1:a10") - the
""argument ofjoinmeans there no space in output i.e. 0011000000
alternative method without using array
sub findfaults() dim rng range, cl range, faultlocations string set rng = range("a1:a1000") faultlocations = "faults found in following cell(s):" & vbcrlf & vbcrlf if worksheetfunction.countif(rng, "x") = 0 msgbox "no fault found" else each cl in rng if cl = "x" faultlocations = faultlocations + "cell: " & cl.address & vbcrlf end if next cl end if msgbox faultlocations end sub
Comments
Post a Comment