Type mismatch error

dsusercs

New Member
Joined
Mar 27, 2013
Messages
9
Hi,

I have a file from which I'm extracting the lines that start with "#### STAGE:" and then to extract the string that is after "#### STAGE:". When I run the below VBA code, I get an error as "Type mismatch". I tried to resolve it but couldn't crack. Any help would be really appreciated.

Sub test()
Dim fn As String, txt As String, a() As String
Dim i As Long, ii As Long, iii As Long, n As Long, x, y

fn = "E:\DSTest\CIGNA\IMAGE_CHG_CAP_LKP.dsx"
delim = vbTab
temp = CreateObject("Scripting.FileSystemObject").OpenTextFile(fn).ReadAll
x = Split(temp, vbCrLf)

ReDim a(1 To UBound(x) + 1, 1 To 100)
For i = 0 To UBound(x)
If InStr(1, x(i), "#### STAGE: ", 1) > 0 Then
n = n + 1: y = Split(x(i), delim)
For ii = 0 To UBound(y)
a(n, ii + 1) = y(ii)
End If
Next

If n > 0 Then
b = Mid(a, 13, 1) --> This line gives the error
Sheets(1).Cells(1).Resize(n, 100).Value = b
End If
End Sub

If I run the above without "b = Mid(a, 13, 1)" it runs fine.
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
a is an array so you can't take the 13th letter of it. You have to loop if you need to manipulate all the array elements.
 
Upvote 0
Thanks for your clarification RoryA. Would you mind giving the code? I have written the above with the help of my friend who is not available now. I have to get the content that follows "#### STAGE: " i.e. starting from 13th position for each row that is fetched.
 
Upvote 0
It's hard to be sure since there is no way that the code you posted would run at all since it wouldn't compile, but probably something like:
Rich (BB code):
If n > 0 Then
for i = lbound(a, 1) to ubound(a, 1)
a(i, 1) = mid(a(i, 1), 13)
next i
Sheets(1).Cells(1).Resize(n, 100).Value = a
End If
 
Upvote 0

Forum statistics

Threads
1,214,917
Messages
6,122,233
Members
449,075
Latest member
staticfluids

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