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

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
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,215,236
Messages
6,123,799
Members
449,127
Latest member
Cyko

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