Message box go to cell

m1ngle

New Member
Joined
Mar 17, 2015
Messages
16
Hello all;

I have a macro searching for errors throughout a worksheet. When an error is returned a message box is displayed indicating the location of the error. I would like the box to center over the offending cell. Is this possible?

What I have so far is

Code:
Sub CheckNames()
    Dim r As Long, c As Range
    'Dim emptyRow As Boolean


     If r_start = 0 Then r_start = 19


     With ActiveSheet
        For r = r_start To 5000
            'Checks entire row for data. User may skip rows when entering data.
            If WorksheetFunction.CountA(.Range(.Cells(r, 1), .Cells(r, 33))) > 0 Then
                If ((.Cells(r, 2) = "") <> (.Cells(r, 3) = "")) Or _
                   ((.Cells(r, 2) = "") = (.Cells(r, 4) = "")) Then
                    'UserForm20.Show
                    ActiveSheet.Range (.Cells(r, 2))
                    MsgBox "Please fill in First and Last Name or HCO in Row " & r & ".", vbOKCancel, "First and Last Name or HCO"
                    If vbCancel Then
                    HCPAddress
                    End If
                    
                End If
            End If
        Next
    End With
'Call HCPAddress
End Sub

The line "ActiveSheet.Range(.Cells(r,2)) always throws an error. Does anyone have any ideas?

Thanks!
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
I don't think you can choose where to place a regular msgbox. You can use a Userform instead, and you should be able to change the position of that. But if you just want the cursor to jump to the offending cell to alert the user, you could just replace the line that is giving you trouble with:

Code:
Cells(r, 2).Activate
 
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,176
Members
451,543
Latest member
cesymcox

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