Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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,245,246,247,248,249,250,25 1,252,253,254,255,256,257,258,259,260,261,262,263, 264,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. |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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, 251,252,253,254,255,256,257,258,259,260,261,262,26 3,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 |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi again Matt,
Ok, I tried yours and it works fine. If you look at the "Addendum" post I did below, you'll see my tester piece that works well too. Which is why I cannot understand why there's a problem. I'd used the same variable names, same functions, same structures, etc.... and the only difference is the operations that occur. And even before I placed the whole code together, I'd tested the operations because I wanted no troubles later. With each failure I went back, tried something else, etc.... until I got a working model. Then, because I had three version of this, I tested all 3 final variations, on worksheets that'd be affected by each of the three, multiple times-- in its final state that'd be released for use-- and they worked, really well-- exactly as expected. Today was the first time I tried using it in the course of my daily operations since I'd finished it because of how busy I'd been since completing them. I see the only real change was that you used different variable names, and InStrRev in your left function, and then placed hyphens in two of the array variable elements. With the mismatch error, I do not get the large window, allowing me to debug, end, etc...and that states the error number-- which I think is 13. I only get a small, 1 x 1-1/2 window that just says compile error, type mismatch, and has only an ok, and a help button on it. Then, you are correct, I did not place the entire macro in my initial post. Here is that macro, in its entirety. ------------------------------------------------------------------------------------ Sub AbstPgStUp_Footer(Control As IRibbonControl) ' AbstPgStUp_Footer Macro 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) ' this appears to remove the existing file's extension 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,245,246,247,248,249,250,25 1,252,253,254,255,256,257,258,259,260,261,262,263, 264,265½,266", ",") 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 '------------------------------------------------ .RightFooter = "&""Arial,Bold""&14Page &P of &N" & Chr(10) & "Tab: &A" .LeftMargin = Application.InchesToPoints(1.25) .RightMargin = Application.InchesToPoints(0.25) .TopMargin = Application.InchesToPoints(0.5) .BottomMargin = Application.InchesToPoints(0.5) .HeaderMargin = Application.InchesToPoints(0.25) .FooterMargin = Application.InchesToPoints(0.25) .Orientation = xlLandscape .PaperSize = xlPaperLegal .FirstPageNumber = xlAutomatic .FitToPagesWide = 1 .FitToPagesTall = False .ScaleWithDocHeaderFooter = True .AlignMarginsHeaderFooter = True End With End Sub ------------------------------------------------------------------------------------ The only parts I'd initially left out were the page set up portions, near the bottom, as you can now see, that are pretty standard. Thanks again for your help..... it really is appreciated. BEst. " wrote: 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,25 0,251,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,2 49," & _ "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 |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Steve
I tested the code below and I didn't recived any errors. When the code errors out, which line is highlighted on clicking debug? BTW: You turn off screenupdating, but you never turns it on again. As good programming practice you should always declare all variables in the top of the sub. Hopes this helsp. --- Per "Steve" skrev i meddelelsen ... Hi again Matt, Ok, I tried yours and it works fine. If you look at the "Addendum" post I did below, you'll see my tester piece that works well too. Which is why I cannot understand why there's a problem. I'd used the same variable names, same functions, same structures, etc.... and the only difference is the operations that occur. And even before I placed the whole code together, I'd tested the operations because I wanted no troubles later. With each failure I went back, tried something else, etc.... until I got a working model. Then, because I had three version of this, I tested all 3 final variations, on worksheets that'd be affected by each of the three, multiple times-- in its final state that'd be released for use-- and they worked, really well-- exactly as expected. Today was the first time I tried using it in the course of my daily operations since I'd finished it because of how busy I'd been since completing them. I see the only real change was that you used different variable names, and InStrRev in your left function, and then placed hyphens in two of the array variable elements. With the mismatch error, I do not get the large window, allowing me to debug, end, etc...and that states the error number-- which I think is 13. I only get a small, 1 x 1-1/2 window that just says compile error, type mismatch, and has only an ok, and a help button on it. Then, you are correct, I did not place the entire macro in my initial post. Here is that macro, in its entirety. ------------------------------------------------------------------------------------ Sub AbstPgStUp_Footer(Control As IRibbonControl) ' AbstPgStUp_Footer Macro 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) ' this appears to remove the existing file's extension 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,245,246,247,248,249,250,25 1,252,253,254,255,256,257,258,259,260,261,262,263, 264,265½,266", ",") 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 '------------------------------------------------ .RightFooter = "&""Arial,Bold""&14Page &P of &N" & Chr(10) & "Tab: &A" .LeftMargin = Application.InchesToPoints(1.25) .RightMargin = Application.InchesToPoints(0.25) .TopMargin = Application.InchesToPoints(0.5) .BottomMargin = Application.InchesToPoints(0.5) .HeaderMargin = Application.InchesToPoints(0.25) .FooterMargin = Application.InchesToPoints(0.25) .Orientation = xlLandscape .PaperSize = xlPaperLegal .FirstPageNumber = xlAutomatic .FitToPagesWide = 1 .FitToPagesTall = False .ScaleWithDocHeaderFooter = True .AlignMarginsHeaderFooter = True End With End Sub ------------------------------------------------------------------------------------ The only parts I'd initially left out were the page set up portions, near the bottom, as you can now see, that are pretty standard. Thanks again for your help..... it really is appreciated. BEst. " wrote: 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,25 0,251,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,2 49," & _ "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 |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
As an addendum,
My primary samples work fine, and have no troubles. And initially, my final macro worked well too. I'd tested it three or four times after I put it in place and had no errors. This is why I don't understrand what's wrong. Thank you. Code below. ------------------------------------------------------ Dim SSide As String Dim fname As String Dim fname1 As String Dim MyClmVar 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) MyClmVar = fname fname1 = Mid(fname, InStr(fname, "-") + 1) 'removes everything except last 3 digits of file name sArray = Split("231,232,233,234,235,236,237,237A,238,239,24 0,241,242,243,243½,244,245,246,247,248,249,250,25 1,252,253,254,255,256,257,258,259,260,261,262,263, 264,265½,266", ",") If UBound(Filter(sArray, fname1)) = 0 Then MsgBox "you're working with claim: " & MyClmVar & SSide Else MsgBox "you're working with claim: " & MyClmVar End If |
#8
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
In my posted code the array was an array of Text. You sArray is a mixture of
numbers and Text. InStr() should have string arguments. Perhaps VBA is have problems handling the mixed array. -- Gary''s Student - gsnu200840 "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,245,246,247,248,249,250,25 1,252,253,254,255,256,257,258,259,260,261,262,263, 264,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. |
#9
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Gary,
You're right, it was actually Rick Rothstein's version that I used. Please accept my apologies for confusing the issue. http://www.microsoft.com/communities...7-516530cae40a I ended up using the version without the loop for the sake of time. I'd like to finish this discussion in the morning. I hope someone can help. Again, thank you for help-- it's been immensely helpful. "Gary''s Student" wrote: In my posted code the array was an array of Text. You sArray is a mixture of numbers and Text. InStr() should have string arguments. Perhaps VBA is have problems handling the mixed array. -- Gary''s Student - gsnu200840 "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,245,246,247,248,249,250,25 1,252,253,254,255,256,257,258,259,260,261,262,263, 264,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. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Gary's Student Part 3 or Anyone else | Excel Discussion (Misc queries) | |||
Map Network Drive FAO Gary's Student | Excel Discussion (Misc queries) | |||
To Gary's Student | Excel Discussion (Misc queries) | |||
To: Gary's Student cell address reply | Excel Discussion (Misc queries) | |||
Is Gary's Student here | Excel Discussion (Misc queries) |