0

I'm working on excel VBA school assignment and I have an issue and can't seem to find answer online. I have database table that holds information, in certain location I have constant array of ={false, true, false} and I need it to convert it to VBA array TF(1 to 3) TF(1) should have value of false TF(2) should have value of true TF(3) should have value of false so far my code looks like this:

Sub trying()
Dim TF(1 To 3) As String
Set targetWorksheet = Worksheets("duomBazeSheet")
Worksheets("duomBazeSheet").Activate

With targetWorksheet
    TF(1) = .Cells(2, 8).Value
    MsgBox (TF(1))

End With
End Sub

"duomBazeSheet" is a sheet that has all data in it and target location is (2, 8)

any ideas?

edit: here's link how sheet looks : array is highlighted https://imgur.com/a/lII3c

4
  • Looks like it should work. Where's the problem? Commented Nov 28, 2017 at 19:47
  • it gets only 1st value, i want to print 2nd value (true) Commented Nov 28, 2017 at 19:50
  • what were you expecting? You are assigning a value to the array from the worksheet Commented Nov 28, 2017 at 19:51
  • you need to loop the array Commented Nov 28, 2017 at 19:52

2 Answers 2

2

Based on a feature called Evaluate one can do this

Dim tf
tf = Application.Evaluate("{True,False,True}")

Given the formula text in H2 try this ...

Sub Test()


    Dim tf
    tf = Application.Evaluate(ActiveSheet.Cells(2, 8).Formula)

    Dim i
    For i = LBound(tf) To UBound(tf)
        MsgBox tf(i)
    Next i

End Sub
Sign up to request clarification or add additional context in comments.

3 Comments

it's nice, sorry to post same link again, I have array highlighted : imgur.com/a/lII3c that's my issue :( it's constant array that needs to be transfered to vba it's not in different lines
or just tf = Evaluate([duomBazeSheet!H2].Formula)
it gives me this :( "Thanks for the feedback! Votes cast by those with less than 15 reputation are recorded, but do not change the publicly displayed post score."
0

The following code declares and populates a one-dimensional array with the values false, true, false. The For Loop will display each element at the end. It is unclear where you want to place these values.

Sub trying()
    Dim TF As Variant
    Dim i As Long
    Dim targetWorksheet As Worksheet

    Set targetWorksheet = Worksheets("duomBazeSheet")

    With targetWorksheet
        TF = Split(.Cells(2, 8).Value, Chr$(10)) 'Chr$(10) is a carriage return
    End With

    For i = LBound(TF) To UBound(TF)
        MsgBox TF(i)
    Next i

End Sub

6 Comments

Why set the array values as Strings and not Booleans?
@Tom, agreed. I don't make the requirements, I just follow along.
I know, but i need to get false true false, from the constant array (={false, true, false}) from the sheet here's the sheet imgur.com/a/lII3c
Or use the " " delimiter if the array does not have commas.
hmm, it only gets false value
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.