Results 1 to 5 of 5
  1. #1
    Star Lounger
    Join Date
    Nov 2003
    Location
    Tampa, Florida, USA
    Posts
    62
    Thanks
    0
    Thanked 0 Times in 0 Posts
    All of a sudden I'm getting a type mismatch error on some code that has been running fine for months. Any ideas what can be wrong?

    MyInput = Application.InputBox(Prompt:="Enter the Maximum Compensation Limit: No $$ Signs, No Commas ", _
    Title:="Compensation Limit", Type:=1)
    On Error GoTo 0
    a = Range("I2000").End(xlUp).Row
    For b = a To 3 Step -1
    If Range("I" & b) > MyInput Then
    'data will be limited to User Input
    Range("I" & b).Value = MyInput
    End If
    Next b
    On Error Resume Next

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    Does one of the cells in column I contain an error value such as #N/A, #ERR or #REF?

  3. #3
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,055
    Thanks
    2
    Thanked 417 Times in 346 Posts
    [quote name='lawrence_groves' post='773358' date='02-May-2009 08:25']All of a sudden I'm getting a type mismatch error on some code that has been running fine for months. Any ideas what can be wrong?[/quote]
    Hi Lawrence,

    Try:
    Code:
    MyInput = CSng(Application.InputBox(Prompt:="Enter the Maximum Compensation Limit:", _
      Title:="Compensation Limit", Type:=1))
    On Error GoTo 0
    a = Range("I2000").End(xlUp).Row
    For b = a To 3 Step -1
      If IsNumeric(Range("I" & b)) Then
    	'data will be limited to User Input
    	If Range("I" & b) > MyInput Then Range("I" & b).Value = MyInput
      Else
       Range("I" & b).Value = MyInput
      End If
    Next b
    Note that I've used the CSng type conversion. With this, it doesn't matter whether the user inputs $ signs or commas. By testing the type of data in the reference cell, your present error if N/A# etc is avoided - you may want to explicitly insert your values into such cells (as my code does), but you can delete the 'Else Range("I" & B ).Value = MyInput' code if you don't want to do that.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  4. #4
    Star Lounger
    Join Date
    Nov 2003
    Location
    Tampa, Florida, USA
    Posts
    62
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [quote name='HansV' post='773360' date='01-May-2009 22:32']Does one of the cells in column I contain an error value such as #N/A, #ERR or #REF?[/quote]


    That was it There was a N/A in one of the cells.
    Thanks Hans

  5. #5
    Star Lounger
    Join Date
    Nov 2003
    Location
    Tampa, Florida, USA
    Posts
    62
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [quote name='macropod' post='773365' date='01-May-2009 22:59']Hi Lawrence,

    Try:
    Code:
    MyInput = CSng(Application.InputBox(Prompt:="Enter the Maximum Compensation Limit:", _
      Title:="Compensation Limit", Type:=1))
    On Error GoTo 0
    a = Range("I2000").End(xlUp).Row
    For b = a To 3 Step -1
      If IsNumeric(Range("I" & b)) Then
    	'data will be limited to User Input
    	If Range("I" & b) > MyInput Then Range("I" & b).Value = MyInput
      Else
       Range("I" & b).Value = MyInput
      End If
    Next b
    Note that I've used the CSng type conversion. With this, it doesn't matter whether the user inputs $ signs or commas. By testing the type of data in the reference cell, your present error if N/A# etc is avoided - you may want to explicitly insert your values into such cells (as my code does), but you can delete the 'Else Range("I" & B ).Value = MyInput' code if you don't want to do that.[/quote]


    I'll give it a try as I have several sections of similar code throughout the program
    Thanks

Posting Permissions

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