Getting Debug on VBA from cells format?

zone709

Well-known Member
Joined
Mar 1, 2016
Messages
2,079
Office Version
  1. 365
Platform
  1. Windows
Hi I get a break down below. What I do is some matching if values match.

On a normal sheet it works fine with the numbers, but I am trying to run it off of numbers that formulas are pulling in.

The thing is im not sure if the break is telling me this or its the cell formats


Code:
Sub Run()   
    Dim myFndCll As Range
    Dim myNumID As String
    Dim myAmount As Double
    Dim lrow As Long
    lrow = Cells(Rows.count, "A").End(xlUp).Row
    
    For LngLp = 2 To lrow
    myNumID = Cells(LngLp, "A") 'Get New Value
  [COLOR=#b22222]  myAmount = Cells(LngLp, "A").Offset(, 1)  <------Breaks here[/COLOR]
    
    Set myFndCll = Columns(3).Find(What:=myNumID, _
                    LookIn:=xlValues, _
                    LookAt:=xlWhole)
                    
    If myFndCll Is Nothing Then
       'Value doesn't exist in column C so highlight value in column A
          Cells(LngLp, "A").Interior.ColorIndex = 4
    Else
        If myAmount <> myFndCll.Offset(, 1) Then
            myFndCll.Offset(, 1).Interior.ColorIndex = 6
            Cells(LngLp, "A").Offset(, 1).Interior.ColorIndex = 6
        End If
    End If
    Next LngLp

End Sub
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Are all your values in column B numeric?
If not, you will have trouble, as you have declared myAmount to be "Double" (so it will not accept text).

If that is not the issue, please tell us the exact error message you are seeing.
 
Upvote 0
im not sure i have that column all in general and those formulas are also pulling numbers from general


Run-time error '13':

Type mismatch
 
Upvote 0
I added some error handling to your code. When you run it, it should tell you exactly which cell is giving you issues. What is the value in that cell?
Code:
Sub MyRun()

    Dim myFndCll As Range
    Dim myNumID As String
    Dim myAmount As Double
    Dim lrow As Long
    lrow = Cells(Rows.Count, "A").End(xlUp).Row

    On Error GoTo err_chk
    For LngLp = 2 To lrow
        myNumID = Cells(LngLp, "A") 'Get New Value
        myAmount = Cells(LngLp, "A").Offset(, 1)
    
        Set myFndCll = Columns(3).Find(What:=myNumID, _
                    LookIn:=xlValues, _
                    LookAt:=xlWhole)
                    
        If myFndCll Is Nothing Then
       'Value doesn't exist in column C so highlight value in column A
            Cells(LngLp, "A").Interior.ColorIndex = 4
        Else
            If myAmount <> myFndCll.Offset(, 1) Then
                myFndCll.Offset(, 1).Interior.ColorIndex = 6
                Cells(LngLp, "A").Offset(, 1).Interior.ColorIndex = 6
            End If
        End If
    Next LngLp
    On Error GoTo 0

    Exit Sub
    
err_chk:
    If Err.Number = 13 Then
        MsgBox "Error with cell: " & Cells(LngLp, "A").Offset(, 1).Address
    Else
        MsgBox Err.Number & ":" & Err.Description
    End If
    
End Sub
 
Upvote 0
ok after running your code. The error in the B columns come up if the cell is empty. So what i did is add a number for the formula to pull in and ran it again. It then looks for the next empty cell in B and then tells you what it is.

My orginal code if i have numbers in the first 4 columns and if a number was empty in B. It left it alone. So not sure why not im getting a debug for column B. I just ran my code on a new sheet with just number as you can see row 4 doesntmatch so it goes yellow. B5 empty but no debug. Just trying to get this to work on my other sheet where the formuals are pulling the nmbers in.


Excel 2016 (Windows) 32 bit
[COLOR=[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] ]A[/COLOR]​
[COLOR=[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] ]B[/COLOR]​
[COLOR=[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] ]C[/COLOR]​
[COLOR=[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] ]D[/COLOR]​
[COLOR=[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] ]1[/COLOR]​
[COLOR=[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] ]2[/COLOR]​
2​
5​
2​
5​
[COLOR=[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] ]3[/COLOR]​
23​
6​
23​
6​
[COLOR=[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] ]4[/COLOR]​
52​
2​
52​
3​
[COLOR=[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] ]5[/COLOR]​
5​
5​
[COLOR=[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] ]6[/COLOR]​
6​
23​
6​
23​
[COLOR=[URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FFFFFF]#FFFFFF[/URL] ]7[/COLOR]​
7​
2​
7​
2​

<tbody>
</tbody>
Sheet: Sheet1

<tbody>
</tbody>


Have a feeling its the formatting of the cells dont know why
 
Last edited:
Upvote 0
Are those blank really blanks, or are they something like a single space?
It would return that error if you actually have spaces instead of empty cells, as you cannot set the variable "myAmount" equal to a space since you have declared it as a number (Double) in your code.

See if making this change to your original code fixes it:
Code:
myAmount = [COLOR=#ff0000]Val([/COLOR]Cells(LngLp, "A").Offset(, 1)[COLOR=#ff0000])[/COLOR]
 
Upvote 0
ok now its working thanks. It seems i run into these issues sometimes. If what you say that maybe the cell isnt really empty. Is there a way to fix it on the actual sheet?
 
Upvote 0
Conceivably, yes. It depends on how exactly the data is being populated.

You can easily check to see if the cell is really empty with the LEN function.
Let's say the cell in question is B4. Then just enter this formula in any blank cell:
=LEN(B4)
If it returns anything other 0, then the cell is not empty.
 
Upvote 0
ok good but if it returns 0. Then is there anything i can do to the format of the cell or whatever to get this cell back to nirmal state as it would pull in a formula on anormal sheet
 
Upvote 0
Then is there anything i can do to the format of the cell or whatever to get this cell back to nirmal state as it would pull in a formula on anormal sheet
I am sorry, but I do not understand what you are asking.
 
Upvote 0

Forum statistics

Threads
1,214,983
Messages
6,122,591
Members
449,089
Latest member
Motoracer88

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