Stop Macro based on Range

Darth Metal

New Member
Joined
Aug 24, 2011
Messages
2
Hello,

I have a simple paste special (values) macro, the data that is to be pasted runs from column AI to AX. In Cell BA I have some formulas that take what I need from the pasted data. As I have other people pasting the data, I would like to know if there is a code that will prevent the user from overwriting the formulas to the right of cell AX (ie someone has copied the wrong report and tries to paste it in the wrong area).

I would like a custom error message to pop up if when someone runs the macro when the result would exceed the AI:AX range and prevent the data from being pasted.

Any help would be greatly appreciated.

Thank you

OS: XP
Office 2010

Existing Macro:
Range("AI3").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End Sub
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
I started looking in to those, and the first path I went down is since you have already selected the range to be copied, the only way to check the size of it is to look at what's in the clipboard. You CAN view the clipboard in VBA, but the results are messy. It comes out as a text string, and I can't see how it is formatted/delimited. I think there is more data stored on the clipboard than we have access to, because for example there is nothing to tell you it is a Range vs. just plain old text.

I think it would be A LOT easier if you attempted to monitor/control the initial selection of the data, rather than try to respond after the fact.

An ugly workaround would be to first paste the data to a hidden empty sheet, then test the column count. If it matches then delete the test data and perform the paste for real in the actual sheet.
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,694
Members
448,979
Latest member
DET4492

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