Limit Copying VBA

jamesmev

Board Regular
Joined
Apr 9, 2015
Messages
233
Office Version
  1. 365
Platform
  1. Windows
I am looking for a VBA solution to limit the number of cells that can be copied at one time within a workbook.

The data contains emails and I am needing to secure them to where only one can be selected at any given time.

Any solutions?
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Hello,

define the key-shortcut "strg-c", e.g. with

Code:
sub T1()
application.OnKey "^c", "MyCopy"
end sub
best in the workbook.open event.

Then to check for the number of rows:

Code:
sub MyCopy()
debug.print selection.rows.count
end sub

regards
 
Upvote 0
This isn't working to only select one cell at a time. It is allowing multiple cells still. I must be missing something, i apologize.
 
Upvote 0
Try this,

Code:
[COLOR=#a9a9a9]'
'this code will limit cells selection to 1 row, 3 columns only, anywhere within this sheet.
'[/COLOR]
[COLOR=#0000cd]Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Const maxRows = 1
Const maxCols = 3

Application.EnableEvents = False
If (Target.Rows.CountLarge > maxRows) Or (Target.Columns.CountLarge > maxCols) Then
    Target.Resize(maxRows, maxCols).Select
End If
Application.EnableEvents = True
End Sub[/COLOR]
 
Upvote 0
You can also place the code in Thisworkbook module.
By doing this, the selection limit will be applied to every worksheet.

Code:
[COLOR=#0000cd]Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
Const maxRows = 1
Const maxCols = 3

Application.EnableEvents = False
If (Target.Rows.CountLarge > maxRows) Or (Target.Columns.CountLarge > maxCols) Then
    Target.Resize(maxRows, maxCols).Select
End If
Application.EnableEvents = True

End Sub[/COLOR]
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,286
Members
452,631
Latest member
a_potato

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