Imported data does not follow data validation rules

wpryan

Well-known Member
Joined
May 26, 2009
Messages
534
Office Version
  1. 365
Platform
  1. Windows
Hi there...I have a worksheet that has some cells that are supposed to be checked by data validation rules (whole number, between 960 and 1040). If one tries to enter values outside the range, the data validation works. However, I have some data imported from a text file (via vba) that go into those cells, and if the values are outside the range, the data is imported without error. Is this something that can be checked by vba?
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Is this something that can be checked by vba?
Most likely.
Can you post the current vba that imports the data? (My signature block below has info about how to best post vba code)

What exactly do you want to happen if some of the data fails the data validation test?
 
Upvote 0
Most likely.
Can you post the current vba that imports the data? (My signature block below has info about how to best post vba code)

What exactly do you want to happen if some of the data fails the data validation test

Most likely.
Can you post the current vba that imports the data? (My signature block below has info about how to best post vba code)

What exactly do you want to happen if some of the data fails the data validation test?
Hello, thanks for your reply. the relevant code is:

VBA Code:
'Copy Park position
                    wsImport.Range("C3:C39").Copy
                    wsData.Range("C10:C46").PasteSpecial Paste:=xlPasteValuesAndNumberFormats
                    wsData.Range("C10:C46").NumberFormat = "0"
                   
                'Park position Rotator Find Position
                   wsImport.Range("B41").Copy
                   wsData.Range("D5").PasteSpecial Paste:=xlPasteValuesAndNumberFormats
                   
                    'Copy OS position
                    wsImport.Range("C43:C79").Copy
                    wsData.Range("G10:G46").PasteSpecial Paste:=xlPasteValuesAndNumberFormats
                    wsData.Range("G10:G46").NumberFormat = "0"

                'OS position Rotator Find Position
                    wsImport.Range("B81").Copy
                    wsData.Range("H5").PasteSpecial Paste:=xlPasteValuesAndNumberFormats
                                      
                'Copy OD position
                    wsImport.Range("C83:C119").Copy
                    wsData.Range("K10:K46").PasteSpecial Paste:=xlPasteValuesAndNumberFormats
                    wsData.Range("K10:K46").NumberFormat = "0"
What I kind of expected to see was the normal message one would see if the data validation criteria is not met:
1674058895155.png
 
Upvote 0
Thanks for the code.

What I kind of expected to see was the normal message one would see if the data validation criteria is not met:
There are a couple of issues involved
  • You are entering several values at once, some of which may be valid and some of which may be invalid.
  • The issue is not specifically related to vba. If you manually copy an entry from elsewhere and paste special - values into a data validated cell the message does not pop up even if that pasted value does not meet the DV criteria.

You could try the following. It should put a red oval around any invalid entries pasted in. Would that be sufficient?
If not I think you would need code to loop through all the cells in those pasted ranges and check each one individually. If you decide that you need that, you would need to explain exactly what you want to happen if, for example, C13, C17, C20:C25, H5 and K40:K42 were invalid and everything else was valid.

VBA Code:
wsData.ClearCircles

' Put all of your copy/pastespecial code here

wsData.CircleInvalid
 
Upvote 0

Forum statistics

Threads
1,214,584
Messages
6,120,387
Members
448,956
Latest member
JPav

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