Trying to implement a messagebox if data is not numeric

TheJay

Active Member
Joined
Nov 12, 2014
Messages
364
Office Version
  1. 2019
Platform
  1. Windows
I have code that checks for gaps and fills them in with sequential numeric data.

VBA Code:
Sub AutoFill()
    Dim R&, F%
        R = ActiveCell.Row
    Do
        F = 1
        R = R + 1
        If IsEmpty(Cells(R, 1)) Then F = 0: Cells(R, 1) = Cells(R - 1, 1)
        If IsEmpty(Cells(R, 2)) Then F = 0: Cells(R, 2) = Cells(R - 1, 2) + 1
    Loop Until F
End Sub

I'm trying to introduce a message box if the user tries activating the code without the selection being numeric data and can't quite get my head around it. If not numeric data, show message and exit sub. If numeric data, continue to process without a message.
VBA Code:
Sub AutoFill()
    Dim R&, F%
        R = ActiveCell.Row
    Do
        F = 1
        R = R + 1
        If Not IsNumeric Then
        MsgBox ("The selection is text, this keyboard shortcut will only work with numbers."), vbOKOnly + vbInformation, "Shortcut Information"
        Exit Sub
        End If
        Else
        If IsEmpty(Cells(R, 1)) Then F = 0: Cells(R, 1) = Cells(R - 1, 1)
        If IsEmpty(Cells(R, 2)) Then F = 0: Cells(R, 2) = Cells(R - 1, 2) + 1
        Loop Until F
End Sub
 
Without the data & code in a wb, hard to follow what you're saying. Seems that is, you got it to work but aren't sure why. That I can't answer since I have no idea what's in any R row. I still don't see how Do Until F can work reliably. Anyway, you've marked it as solved and seem to like how it functions so I guess that's all that matters.
 
Upvote 0

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off

Forum statistics

Threads
1,214,923
Messages
6,122,283
Members
449,075
Latest member
staticfluids

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