LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 135
Default follow up to Gary's Student macro

On Mar 19, 4:51*pm, Steve wrote:
Hi MAtt,
Thank you for the quick response.
I looked-- no, my require variable declaration is not checked. And no, I do
not have option explicit anywhere in the macro module.
Then, I did try setting my sArray to a declared type.
Neither dim sArray as variant, nor as string worked.
Any other ideas?
Again, thanks.



" wrote:
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,2 51,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- Hide quoted text -


- Show quoted text -


Steve,

Require Varialbe Declaration forces you to dimension all of your
variables. Checking this option will automatically write "Option
Explicit" at the top of any new Module you create. As you code,
Option Explicit forces the editor to inform you if you used a variable
that does not match the variables you dimensioned. This option is a
nice way of performing a "double check" against what you are doing in
real time, before you run your code (as well as when you run your
code).

I'm not quite sure why you are getting an error. Is it still a Type
Mismatch error? I copied your code, created a workbook called
"test-256.xls", and ran the code below. I didn't run into any
errors. You can copy and paste my code below and see if you are error
free; otherwise, your error may be coming from somewhere else in your
procedure. (I'm assuming you you didn't paste the entire procedure in
this post).

Sub TestCode()

Dim strSide As String
Dim strFileName As String
Dim strFileName1 As String
Dim strMyClaim As String
Dim varMyArray As Variant

strSide = ", P.11489, C.4827"
strFileName = ActiveWorkbook.Name
strFileName = Left(strFileName, InStrRev(strFileName, ".") - 1)
strMyClaim = strFileName
strFileName1 = Mid(strFileName, InStr(strFileName, "-") + 1)

varMyArray = Split("231,232,233,234,235,236,237,237A,238,239," & _
"240,241,242,243,243½,244,24*5,246,247,248,249 ," & _
"250,251,252,253,254,255,256,257,258,259,260," & _
"261,262,263,2*64265½,266", ",")

If UBound(Filter(varMyArray, strFileName1)) = 0 Then
MsgBox "you're working with claim: " & strMyClaim & strSide
Else
MsgBox "you're working with claim: " & strMyClaim
End If

End Sub

Let me know if this helps you pin down your problem.

Matt
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Gary's Student Part 3 or Anyone else ohnesorge Excel Discussion (Misc queries) 3 March 12th 09 04:04 PM
Map Network Drive FAO Gary's Student leerem Excel Discussion (Misc queries) 4 January 14th 09 02:53 PM
To Gary's Student Michael Fosmire [MSFT] Excel Discussion (Misc queries) 2 May 17th 07 02:09 PM
To: Gary's Student cell address reply ppbedz Excel Discussion (Misc queries) 5 April 17th 06 10:47 PM
Is Gary's Student here zmr325 Excel Discussion (Misc queries) 8 November 30th 05 12:17 PM


All times are GMT +1. The time now is 06:36 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"