Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 69
Default Data validation when pasting data

Hi,

Using the worksheet change event you can capture the whether the user
has something copied by testing for:

If Application.CutCopyMode = xlCopy Then

This will only = xlcopy when pasting, you are then able to change the
result to fit your formatting as you know what cell the user is in etc.
so you could test the length and append a zero or alternatively
pastevalues which will then take on your validation.

James


pablo bellissimo wrote:
Hi All,

I'm a total newbie with VBA so please be patient!
I need to assign data validation to a single column in a worksheet to ensure
that users can only enter 11 digits but the first one must be a zero. I can
force the text length to be 11 which is fine but when users paste a list
(from another sheet) it overwrites the validation, and drops the leading zero
(due to it being a number).
I can't just change the format to display the leading zero as I need to feed
the full 11 digits into another system.

In summary, does anyone have a bit of code that will prevent users from
pasting anything into the column that does not match the validation criteria?
I dont want to just turn off the paste functionality.

Any help would be greatly appeciated.

Pablo


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 69
Default Data validation when pasting data

Hi Pablo,

No I don't think so, it was a while ago when I used this but
effectively I was trying to do the same as you, I didn't want users to
stop pasting in etc. but still wanted to force a particular format.

To be sure just put Application.cutcopymode = false at the end of your
code, this will do the same as when you hit escape after a value has
been pasted and effectively reset the cutcopymode so it will not
trigger next time, there may be the rare occasion when this would be
annoying for a user but I can't think of one?!

Any problems then give me a shout,

James


pablo bellissimo wrote:
Thanks for the reply james.

Could you just confirm what would happen if a user pasted a value into a
cell and then manually typed a value into the cell below. When they manually
typed the value would the cuptcopymode still = xlCopy even though the user
hadn't actually pasted into the current cell??

" wrote:

Hi,

Using the worksheet change event you can capture the whether the user
has something copied by testing for:

If Application.CutCopyMode = xlCopy Then

This will only = xlcopy when pasting, you are then able to change the
result to fit your formatting as you know what cell the user is in etc.
so you could test the length and append a zero or alternatively
pastevalues which will then take on your validation.

James


pablo bellissimo wrote:
Hi All,

I'm a total newbie with VBA so please be patient!
I need to assign data validation to a single column in a worksheet to ensure
that users can only enter 11 digits but the first one must be a zero. I can
force the text length to be 11 which is fine but when users paste a list
(from another sheet) it overwrites the validation, and drops the leading zero
(due to it being a number).
I can't just change the format to display the leading zero as I need to feed
the full 11 digits into another system.

In summary, does anyone have a bit of code that will prevent users from
pasting anything into the column that does not match the validation criteria?
I dont want to just turn off the paste functionality.

Any help would be greatly appeciated.

Pablo




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 69
Default Data validation when pasting data

Hi Pablo,

Thinking about it, the answer is no as the change event of a worksheet
happens after the user has finished editing a cell but editing a cell
will actually reset the cutcopymode to false anyway so the only time
this should fire is when a user is pasting.

Cheers,

James


wrote:
Hi Pablo,

No I don't think so, it was a while ago when I used this but
effectively I was trying to do the same as you, I didn't want users to
stop pasting in etc. but still wanted to force a particular format.

To be sure just put Application.cutcopymode = false at the end of your
code, this will do the same as when you hit escape after a value has
been pasted and effectively reset the cutcopymode so it will not
trigger next time, there may be the rare occasion when this would be
annoying for a user but I can't think of one?!

Any problems then give me a shout,

James


pablo bellissimo wrote:
Thanks for the reply james.

Could you just confirm what would happen if a user pasted a value into a
cell and then manually typed a value into the cell below. When they manually
typed the value would the cuptcopymode still = xlCopy even though the user
hadn't actually pasted into the current cell??

" wrote:

Hi,

Using the worksheet change event you can capture the whether the user
has something copied by testing for:

If Application.CutCopyMode = xlCopy Then

This will only = xlcopy when pasting, you are then able to change the
result to fit your formatting as you know what cell the user is in etc.
so you could test the length and append a zero or alternatively
pastevalues which will then take on your validation.

James


pablo bellissimo wrote:
Hi All,

I'm a total newbie with VBA so please be patient!
I need to assign data validation to a single column in a worksheet to ensure
that users can only enter 11 digits but the first one must be a zero. I can
force the text length to be 11 which is fine but when users paste a list
(from another sheet) it overwrites the validation, and drops the leading zero
(due to it being a number).
I can't just change the format to display the leading zero as I need to feed
the full 11 digits into another system.

In summary, does anyone have a bit of code that will prevent users from
pasting anything into the column that does not match the validation criteria?
I dont want to just turn off the paste functionality.

Any help would be greatly appeciated.

Pablo



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
custom data validation on cells with data validation values AKrobbins Excel Worksheet Functions 2 June 21st 11 04:20 PM
Data validation vs. cutting pasting Illya Teideman Excel Discussion (Misc queries) 0 August 22nd 07 12:32 PM
Why does data validation not work when pasting data into a cell. rjshelby Excel Discussion (Misc queries) 1 July 31st 06 09:08 PM
Refresh existing data when changed in data validation list problem girl New Users to Excel 1 September 28th 05 10:19 PM
Pasting on Filtered Data Sheets without pasting onto hidden cells CCSMCA Excel Discussion (Misc queries) 1 August 28th 05 01:22 PM


All times are GMT +1. The time now is 05:46 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"