Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

Is there any way to copy cell data validation without using copy & pastespecial commands?

Status
Not open for further replies.

Agent666

Structural
Jul 2, 2008
3,080
0
0
NZ
Hi

As per title, I was wondering if cell data validation settings be copied without a range().copy & range().pastespecial operation in Excel.

Its in an effort to solve a dreaded screen flicker that occurs when forced to copy/paste in this manner (yes I have Application.ScreenUpdating = false). Data validation on sheet(2) is applied to a similar set of cells in sheet(3)

An internet search doesn't turn anything up, no way of reading all the validation settings and then applying the same settings to destination cells, really after something like you can do with number formats using range().numberformat ideally, does anything exist?



Thanks in advance
 
Replies continue below

Recommended for you

You can use the Copy Destination option. Here's some code from one of my spreadsheets (Note: the source and destination are on 2 different sheets):
Code:
Range(Sheet1.Cells(1, 1), Sheet1.Cells(1, 21)).Copy _
    Destination:=Sheet7.Cells(1, 1)
 
Hi thanks for the reply, Iv'e realised the question wasn't asked particularly well.

I just want to copy the validation, value and number format. I can handle the number format and value without selecting cells and pasting. But not the data validation, so if anyone knows a way to do it without selecting a selection and pastespecial operation please let me know.

 
the function at the end was exactly the lead I needed to read and apply only the data validation between source and target ranges. Thanks worked a treat, still have the flashing due to some other dodgy code... one step at a time I guess!
 
still have the flashing due to some other dodgy code

Check out the ScreenUpdating property.

Avoid using Activate and Select methods. Rather reference objects directly, like worksheets and ranges.

For tips from computer professionals, consider posting in Eng-Tips sister site, in the Visual Basic for Applications (Microsoft) forum,
Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
I did figure out what it was in the end, seemed to depend on which subroutine I called the application.screenupdating = true/false from.

Had some code where it would set it to true and then in a further called sub would set it back to false, before returning back to the original sub. Wasn't turning it on/off more than once or anything. Funny thing was in other code doing the same thing had no flashing, so who knows!
 
Status
Not open for further replies.
Back
Top