Copying creates compiling error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Lollygirlie1
    New Member
    • Oct 2006
    • 3

    #1

    Copying creates compiling error

    Good morning,

    I wrote some code today and it compiled fine in one xcel workbook. I copied it and set up the macro in a different workbook. Now it's giving me the following error:

    Argument not optional

    and pointing at my variable to determine the last row used in the tab. What did I do wrong? It's the SAME CODE!

    Here is the entire code:

    Sub UpdateFinal()
    '
    ' UpdateFinal Macro
    ' Written 10/5/2006 to update and sort master list
    '
    Sheets("Master" ).Select
    'Selects Master list
    LastRow = ActiveSheet.Cel ls(65536, 1).End(xlUp).Ro w
    Range("A3", ActiveSheet.Cel ls(LastRow, 26)).Select
    Selection.Delet e
    'Clears all data from "Master" tab
    Sheets("FoHF"). Select
    LastRow = ActiveSheet.Cel ls(65536, 1).End(xlUp).Ro w
    Range("A3", ActiveSheet.Cel ls(LastRow, 26)).Select
    Selection.Copy
    'Copies current information from "FoHF" tab
    Sheets("Master" ).Select
    ActiveSheet.Ran ge("A1").End(xl Down).Offset(1, 0).Select
    ActiveSheet.Pas te
    'Pastes to "Master" tab
    Sheets("RA").Se lect
    Application.Cut CopyMode = False
    LastRow = ActiveSheet.Cel ls(65536, 1).End(xlUp).Ro w
    Range("A3", ActiveSheet.Cel ls(LastRow, 26)).Select
    Selection.Copy
    'Copies current information from "RA" tab
    Sheets("Master" ).Select
    ActiveSheet.Ran ge("A65536").En d(xlUp).Offset( 1, 0).Select
    ActiveSheet.Pas te
    'Pastes to "Master" tab
    Sheets("RE").Se lect
    Application.Cut CopyMode = False
    LastRow = ActiveSheet.Cel ls(65536, 1).End(xlUp).Ro w
    Range("A3", ActiveSheet.Cel ls(LastRow, 26)).Select
    Selection.Copy
    'Copies current information from "RE" tab
    Sheets("Master" ).Select
    ActiveSheet.Ran ge("A65536").En d(xlUp).Offset( 1, 0).Select
    ActiveSheet.Pas te
    'Pastes to "Master" tab
    Sheets("PE").Se lect
    Application.Cut CopyMode = False
    LastRow = ActiveSheet.Cel ls(65536, 1).End(xlUp).Ro w
    Range("A3", ActiveSheet.Cel ls(LastRow, 26)).Select
    Selection.Copy
    'Copies current information from "PE" tab
    Sheets("Master" ).Select
    ActiveSheet.Ran ge("A65536").En d(xlUp).Offset( 1, 0).Select
    ActiveSheet.Pas te
    'Pastes to "Master" tab
    Rows("3:65536") .Select
    Application.Cut CopyMode = False
    Selection.Sort Key1:=Range("C3 "), Order1:=xlAscen ding, Header:=xlGuess , _
    OrderCustom:=1, MatchCase:=Fals e, Orientation:=xl TopToBottom, _
    DataOption1:=xl SortNormal
    'Sorts alphabetically by Manager Name
    End Sub

    HELP!
  • sashi
    Recognized Expert Top Contributor
    • Jun 2006
    • 1749

    #2
    Hi there,

    Argument not optional simply means that you are not passing enough input to your function / sub, kindly refer to below code segment, take care my fren.. :)

    Code:
      Function TestX(ByVal strName as String, ByVal intAge as Integer)
      
      Msgbox strName & " - " & intAge
    
      End Function
    Lets refers to the above Function TestX, you need to pass to arguments, which is the Name & Age, hope you get what am trying to say, good luck.

    Comment

    • Lollygirlie1
      New Member
      • Oct 2006
      • 3

      #3
      Originally posted by sashi
      Hi there,

      Argument not optional simply means that you are not passing enough input to your function / sub, kindly refer to below code segment, take care my fren.. :)

      Code:
        Function TestX(ByVal strName as String, ByVal intAge as Integer)
        
        Msgbox strName & " - " & intAge
      
        End Function
      Lets refers to the above Function TestX, you need to pass to arguments, which is the Name & Age, hope you get what am trying to say, good luck.
      The problem is that it works for the original workbook, but causes the compiling error for the second workbook. Since the code is the same (hooray for copy paste), I don't know why the second workbook won't compile.

      Comment

      • Lollygirlie1
        New Member
        • Oct 2006
        • 3

        #4
        The error was in my variable name (lastRow). Apparently, it's been defined somewhere else in the second work book. All I had to do was declare a new long variable (lr) and replace lastRow with it. Thanks for the help

        Comment

        Working...