Stuck on a simple IsNumeric Test: If Contents of the Clipboard is Numeric Then Proceed Else Exit Sub

realitycheck

New Member
Joined
Aug 29, 2014
Messages
9
I have found ways of testing the contents of the clipboard for all kinds of things, but apparently there's no easy way of testing the clipboard for numeric values.

Basically the user will have something in the clipboard, and if it's not a digit, they made a mistake. My code will error out if there is a non numeric value in the clipboard without giving them feedback of any kind.

So I would like to have a message box pop up if the value in the clipboard is non numeric.

Does anyone have the proper syntax for doing this?

Thanks in advance.
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
I got it...

This code is working for me...

It requires this public function...

Code:
Function IsClipboardEmpty() As Boolean
'function to test if clipboard is empty
    IsClipboardEmpty = (CountClipboardFormats() = 0)
End Function

with this sub...

Code:
Private Sub FindAllIDsButton_Click()

'code to find all IDs button

'prep for search
frmPartLoc.Hide
Sheets("DATA").Select

'Test 1 - Look for empty clipboard first...
 If IsClipboardEmpty Then
 MsgBox "Please Copy ID first"
 frmPartLoc.Show
 Exit Sub
 End If
 
 'Test 2 - Check for numerical values only
   Dim DataObj As MsForms.DataObject
   Set DataObj = New MsForms.DataObject '<~~ Amended as per jp's suggestion

   On Error GoTo Whoa

   '~~> Get data from the clipboard.
   DataObj.GetFromClipboard

   '~~> Get clipboard contents
   MyString = DataObj.GetText(1)
   
   'If it's not numeric
   If Not IsNumeric(MyString) Then
   
MsgBox "The clipboard doesn't contain a valid ID. Copy again and retry."
'return to primary form
frmPartLoc.Show
   Exit Sub
   
        Else 'It's numeric so proceed...
        'go ahead and open the find all form
   f_FindAll.Show
   End If
   
Whoa:
'this should never happen but it's here just in case.
   If Err <> 0 Then MsgBox "Data on clipboard is not text or is empty"
   'return to primary form
   frmPartLoc.Show
   
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,148
Messages
6,123,306
Members
449,095
Latest member
Chestertim

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