String Array Error

DataBlake

Well-known Member
Joined
Jan 26, 2015
Messages
781
Office Version
  1. 2016
Platform
  1. Windows
Code:
Sub test()
Dim textVAR(0 To 5) As String
Dim i as Long

textVAR(0) = "Do"
textVAR(1) = "Re"
textVAR(2) = "Me"
textVAR(3) = "Fa"
textVAR(4) = "So"
textVAR(5) = "La"

For i = LBound(textVAR) To UBound(textVAR)

If textVAR = "Do" Then
msgbox textVAR
Else
msgbox "Nope"
End If

next i
End Sub

if i pull textVAR into the watch window it shows value as "Can't compile module" and type "Empty"
its highlighting the = on the if statement with type mismatch error
 
Last edited:

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
You must indicate the index

Code:
Sub test()
  Dim textVAR(0 To 5) As String
  Dim i As Long
  textVAR(0) = "Do"
  textVAR(1) = "Re"
  textVAR(2) = "Me"
  textVAR(3) = "Fa"
  textVAR(4) = "So"
  textVAR(5) = "La"
  For i = LBound(textVAR) To UBound(textVAR)
    If textVAR[B][COLOR=#ff0000](i)[/COLOR][/B] = "Do" Then
      MsgBox textVAR[B][COLOR=#ff0000](i)[/COLOR][/B]
    Else
      MsgBox "Nope"
    End If
  Next i
End Sub
 
Upvote 0
Because textVAR is an array you cannot use
Code:
If textVAR = "Do" Then
I suspect you mean
Code:
If textVAR(i) = "Do" Then
you'll need to add that to the next line as well
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,179
Members
452,615
Latest member
bogeys2birdies

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top