+ Reply to Thread
Results 1 to 3 of 3

Error message when clicking on a command button asigned a macro

  1. #1
    Registered User
    Join Date
    11-15-2012
    Location
    Illinois
    MS-Off Ver
    Excel 2007
    Posts
    3

    Question Error message when clicking on a command button asigned a macro

    I have a command button with an assigned macro (code listed below) and what I am trying to do is each time I click on the command button I want to 'replace' eleven cells with new data from an array (named cell range) - so I am trying to increment a variable and use it as a counter so every click will advance new data into the appropriate cells. At the moment when I click on the command button I get the following error: "Run-time error'1004': Application-defined or object-defined error"

    I have tried different ways of dimensioning the variable using private, Public, Dim and currently Static but I always get this error? I would appreciate any help?

    Thanks
    Steve

    Sub MileChart()
    '
    ' MileChart Macro


    Static i As Integer
    i = i + 1
    ' Dim i As Integer

    Range("AT3").Select
    ActiveCell.FormulaR1C1 = "=VLOOKUP(R[i]C3,FName,1,FALSE)"
    Range("AU3").Select
    ActiveCell.FormulaR1C1 = "=VLOOKUP(R[i]C1,Array,11,FALSE)"
    Range("AV3").Select
    ActiveCell.FormulaR1C1 = "=VLOOKUP(R[i]C1,Array2,11,FALSE)"
    Range("AW3").Select
    ActiveCell.FormulaR1C1 = "=VLOOKUP(R[i]C1,Array3,11,FALSE)"
    Range("AX3").Select
    ActiveCell.FormulaR1C1 = "=VLOOKUP(R[i]C1,Array4,11,FALSE)"
    Range("AY3").Select
    ActiveCell.FormulaR1C1 = "=VLOOKUP(R[i]C1,Array5,11,FALSE)"
    Range("AZ3").Select
    ActiveCell.FormulaR1C1 = "=VLOOKUP(R[i]C1,Array6,11,FALSE)"
    Range("BA3").Select
    ActiveCell.FormulaR1C1 = "=VLOOKUP(R[i]C1,Array7,11,FALSE)"
    Range("BB3").Select
    ActiveCell.FormulaR1C1 = "=VLOOKUP(R[i]C1,Array8,11,FALSE)"
    Range("BC3").Select
    ActiveCell.FormulaR1C1 = "=VLOOKUP(R[i]C1,Array9,11,FALSE)"
    Range("BD3").Select
    ActiveCell.FormulaR1C1 = "=VLOOKUP(R[i]C1,Array10,11,FALSE)"
    Range("BD4").Select

    End Sub

  2. #2
    Registered User
    Join Date
    11-15-2012
    Location
    Illinois
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Error message when clicking on a command button asigned a macro

    I should probably add that when you press 'debug' after seeing the error message it highlights the line that reads: "ActiveCell.FormulaR1C1 = "=VLOOKUP(R[i]C3,FName,1,FALSE)"
    Steve

  3. #3
    Registered User
    Join Date
    11-15-2012
    Location
    Illinois
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Error message when clicking on a command button asigned a macro

    I should probably add that when you press 'debug' after seeing the error message it highlights the line that reads: "ActiveCell.FormulaR1C1 = "=VLOOKUP(R[i]C3,FName,1,FALSE)"

    It may also help to know that when I manually replace the variable 'i' with a constant say '2' and then click on the command button it works perfectly so there is something wrong with the way I am
    using the variable.
    Steve

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1