View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
[email protected] meh2030@gmail.com is offline
external usenet poster
 
Posts: 135
Default follow up to Gary's Student macro

On Mar 19, 3:32*pm, Steve wrote:
hi all.
On the 10th of this month, Gary's Student provided me with a macro that
helped me do an array so I could do a comparison.
This morning I tried my final version of the macro and it threw a mismatch
error.
I looked at it, and I cannot identify the error's source.
As such, would you pease help me track this thing down so I can get it
working? It worked fine immediately following my final tweak as I put it into
place.

The code for the initial components are below.
Gary's code.
----------------------------------------------------------------
-------------------------------------------------------------

Sub StringAlong()
sArray = Split("alpha,beta,gamma,delta,zeta,eta,theta", ",")
sample = "mm"
For i = LBound(sArray) To UBound(sArray)
If InStr(sArray(i), sample) 0 Then
MsgBox ("found it")
Exit Sub
End If
Next
MsgBox ("did not find it")
End Sub
---------------------------------
-----------------------------------

my variation below.

------------------------------------
-------------------------------

Dim fname As String
Dim fname1 As String
Dim myClmVar1 As String

Dim SSide As String
SSide = ", P.11489, C.4827"

fname = ActiveWorkbook.Name 'this looks at the existing file's name

'remove extension
fname = Left(fname, InStr(fname, ".") - 1)

fname1 = Mid(fname, InStr(fname, "-") + 1) 'removes everything except last 3
digits of file name

'
Dim MyDate As Date

MyDate = Date
Dim MyClmVar As String
* * MyClmVar = fname

myClmVar1 = MyClmVar & SSide
*sArray =
Split("231,232,233,234,235,236,237,237A,238,239,24 0,241,242,243,243½,244,24*5,246,247,248,249,250,25 1,252,253,254,255,256,257,258,259,260,261,262,263, 2*64,265½,266", ",")
'the sArray is where the error is thrown, as a mismatch.
*Application.ScreenUpdating = False

* * With ActiveSheet.PageSetUp
* * * * .PrintTitleRows = "$1:$7"
* * * * .PrintTitleColumns = ""
* * End With
* * ActiveSheet.PageSetUp.PrintArea = ""
* * With ActiveSheet.PageSetUp
* * * * .RightHeader = "Printed on: &D"
* * * * .LeftFooter = "&""Arial,Bold""&14 " & MyDate
* * * * '-------------------------------------------------
* * * * If UBound(Filter(sArray, fname1)) = 0 Then
* * * * * * .CenterFooter = "&""Arial,Bold""&14 " & myClmVar1
* * * * * * * * 'MsgBox "your output is: " & myClmVar1
* * * * * * Else
* * * * * * .CenterFooter = "&""Arial,Bold""&14 " & MyClmVar
* * * * * * * * 'MsgBox "your output is: " & MyClmVar
* * * * End If
* * * * '------------------------------------------------
........................
end with

Thank you.


Steve,

Do you have "Require Variable Declaration" checked in Tools | Options
(Editor page)? Or in other words, does your code module have "Option
Explicit" in it? If it does, then you are likely getting a type
mismatch for your sArray variable. I don't see a Dim statement for
this variable in your code, but I'm guessing you declared sArray As
String. Change your data type to Variant (i.e. Dim sArray As Variant)
and see if it will work.

Best,

Matt Herbert