Reading a cell with a Run-time error '6'

USAMax

Well-known Member
Joined
May 31, 2006
Messages
853
Office Version
  1. 365
Platform
  1. Windows
I am reading imported data that occasionally separates a conformation number into its own cell. Thus when I read it I get the dreaded, "Run-time error '6'".

If I know it is a number and the previous cell ends with, "Confirmation #:" or, "confirmation number is" then I can handle it. But I cannot test if it is numeric and IsError(Cells(CurRow + 1, 1)) returns FALSE.

How do I test for the Run-time error '6'?

Here are some of the values in the cells I am dealing with:
30872268079
30042067910
530560067953
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
The usual way to handle it would be something like this:

VBA Code:
Sub HandleError6()
    Dim x As Long
    On Error Resume Next
    '
    ' Comment/uncomment the two lines below to test both parts of the IF statement
    x = 2000 * 365    ' Generates a type 6 error
    'x = CLng(2000) * 365    ' Does not generate a type 6 error
    '
    If Err.Number = 6 Then
        '
        ' Handle the type 6 error as appropriate
        '
        MsgBox "Type 6 error occurred"
        Err.Clear
        On Error GoTo 0
    Else
        On Error GoTo 0
        '
        ' No error - Do what you normally do for all the other numbers
        '
        MsgBox "Proceeding normally"
    End If
End Sub
 
Upvote 0
The usual way to handle it would be something like this:

VBA Code:
Sub HandleError6()
    Dim x As Long
    On Error Resume Next
    '
    ' Comment/uncomment the two lines below to test both parts of the IF statement
    x = 2000 * 365    ' Generates a type 6 error
    'x = CLng(2000) * 365    ' Does not generate a type 6 error
    '
    If Err.Number = 6 Then
        '
        ' Handle the type 6 error as appropriate
        '
        MsgBox "Type 6 error occurred"
        Err.Clear
        On Error GoTo 0
    Else
        On Error GoTo 0
        '
        ' No error - Do what you normally do for all the other numbers
        '
        MsgBox "Proceeding normally"
    End If
End Sub
Thank you so much, I guess I did not think past the detection of the error. Now I need to append the number as a string value from the cell below the active cell to the value in the active cell. I tried...
VBA Code:
Cells(CurRow, 1) = Cells(CurRow, 1) & " " & Cells(CurRow + 1, 1).Value
 
Upvote 0
Hard to say really without more information - does it give an error? If yes, what is the error. If no, what's wrong with it. It works ok for me, although for the sake of form you could put

VBA Code:
Cells(CurRow, 1).Value = Cells(CurRow, 1).Value & " " & Cells(CurRow + 1, 1).Value

As Rory indicates, we really need to know how you're reading the value and some sample data to properly tell what's going on.
 
Upvote 0

Forum statistics

Threads
1,226,516
Messages
6,191,496
Members
453,659
Latest member
thomji1

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top