SOLVED

Data Validation Settings fails to apply

%3CLINGO-SUB%20id%3D%22lingo-sub-2238510%22%20slang%3D%22en-US%22%3EData%20Validation%20Settings%20fails%20to%20apply%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2238510%22%20slang%3D%22en-US%22%3E%3CP%3EHope%20someone%20can%20help%20me%20on%20this.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%203%20cells(A1%2CA2%2CA3)%20for%20which%20I%20want%20only%20Whole%20Numbers%20like%201%2C2%2C3%20and%20do%20not%20want%20decimals%20like%200.1%20or%200.5%20and%20neither%20want%20alpha%20chars%20so%20I%20have%20set%20Data%20Validation%20for%20these%20cells%20to%20Whole%20Number.%20This%20seems%20to%20work%20fine%20when%20I%20try%20to%20enter%20any%20non%20whole%20number%20values%20manually%20it%20throws%20an%20error%20and%20accepts%20only%20whole%20numbers%20so%20till%20here%20this%20is%20good.%20But%20when%20I%20copy%20from%20any%20other%20excel%20or%20non%20excel%20application%20and%20paste%20in%20these%20cells%20it%20accepts%20the%20values%20and%20let%20it%20paste%20ignoring%20the%20data%20validation%20settings.%20So%20I%20added%20the%20below%20code%20to%20restrict%20it%20to%20only%20numbers%20but%20this%20code%20is%20allowing%20decimals%20as%20well%20since%20the%20funtion%20is%20IsNumeric%20and%20blocking%20only%20alpha%20chars.%20Is%20there%20any%20function%20which%20allows%20only%20Whole%20Numbers.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E'Only%20numeric%20values%3CBR%20%2F%3EConst%20CELL_ADDRESS%20%3D%20%22%24A%241%3A%24A%243%22%20'change%20range%3CBR%20%2F%3EIf%20Not%20Application.Intersect(Target%2C%20Range(CELL_ADDRESS))%20Is%20Nothing%20Then%3CBR%20%2F%3EIf%20Not%20Int(Target.Value)%20Then%3CBR%20%2F%3EMsgBox%20%22You%20must%20enter%20only%20numeric%20values%22%2C%20vbCritical%2C%20%22Invalid%20Input%22%3CBR%20%2F%3ETarget.Value%20%3D%20vbNullString%3CBR%20%2F%3EEnd%20If%3CBR%20%2F%3EEnd%20If%3C%2FP%3E%3CP%3EEnd%20Sub%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2238510%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMacros%20and%20VBA%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2238560%22%20slang%3D%22en-US%22%3ERe%3A%20Data%20Validation%20Settings%20fails%20to%20apply%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2238560%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F885996%22%20target%3D%22_blank%22%3E%40Abdullah_Shurjeel%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ETry%20this%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-visual%22%3E%3CCODE%3EPrivate%20Sub%20Worksheet_Change(ByVal%20Target%20As%20Range)%0A%20%20%20%20'Only%20numeric%20values%0A%20%20%20%20Const%20CELL_ADDRESS%20%3D%20%22A1%3AA3%22%20'change%20range%0A%20%20%20%20Dim%20rng%20As%20Range%0A%20%20%20%20Dim%20f%20As%20Boolean%0A%20%20%20%20If%20Not%20Intersect(Target%2C%20Range(CELL_ADDRESS))%20Is%20Nothing%20Then%0A%20%20%20%20%20%20%20%20For%20Each%20rng%20In%20Intersect(Target%2C%20Range(CELL_ADDRESS))%0A%20%20%20%20%20%20%20%20%20%20%20%20If%20Not%20IsNumeric(rng.Value)%20Then%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20f%20%3D%20True%0A%20%20%20%20%20%20%20%20%20%20%20%20ElseIf%20Not%20rng.Value%20%3D%20Int(rng.Value)%20Then%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20f%20%3D%20True%0A%20%20%20%20%20%20%20%20%20%20%20%20End%20If%0A%20%20%20%20%20%20%20%20%20%20%20%20If%20f%20Then%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20MsgBox%20%22You%20must%20enter%20only%20whole%20numbers!%22%2C%20vbCritical%2C%20%22Invalid%20Input%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Application.EnableEvents%20%3D%20False%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Application.Undo%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Application.EnableEvents%20%3D%20True%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Exit%20For%0A%20%20%20%20%20%20%20%20%20%20%20%20End%20If%0A%20%20%20%20%20%20%20%20Next%20rng%0A%20%20%20%20End%20If%0AEnd%20Sub%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2238567%22%20slang%3D%22en-US%22%3ERe%3A%20Data%20Validation%20Settings%20fails%20to%20apply%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2238567%22%20slang%3D%22en-US%22%3ETRIM%20removes%20the%20digits%20after%20the%20decimal%20point.%3CBR%20%2F%3E%3CBR%20%2F%3EMatrix%20formula%3A%3CBR%20%2F%3E%3D%20SUM%20(TRIM%20(A1%3A%20A3))%3CBR%20%2F%3E%3CBR%20%2F%3EAdditional%20Formulas%3A%3CBR%20%2F%3E%3DINT(A1)%3CBR%20%2F%3E%3DTRUNC(A1)%3CBR%20%2F%3E%3DROUND(A1%2C0)%3CBR%20%2F%3E%3CBR%20%2F%3EHope%20I%20was%20able%20to%20help%20you%20with%20this%20info.%3CBR%20%2F%3E%3CBR%20%2F%3ENikolino%3CBR%20%2F%3EI%20know%20I%20don't%20know%20anything%20(Socrates)%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2239253%22%20slang%3D%22en-US%22%3ERe%3A%20Data%20Validation%20Settings%20fails%20to%20apply%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2239253%22%20slang%3D%22en-US%22%3EThis%20is%20great.%20Appreciate%20your%20quick%20response.%3CBR%20%2F%3E%3CBR%20%2F%3EI%20have%20tested%20the%20code%2C%20it%20is%20accepting%20whole%20numbers%20only%20even%20when%20pasted%20from%20other%20excels%20or%20non-excel%20applications.%3CBR%20%2F%3E%3CBR%20%2F%3EI%20have%202%20questions%20here%3A%3CBR%20%2F%3E%3CBR%20%2F%3EQ1%3A%20For%20our%20sample%20code%20we%20have%20range%20of%20cells%20from%20A1%20to%20A3.%20Suppose%20I%20have%20cells%20like%20D8%2C%20G10%2C%20L9%20how%20do%20I%20give%20input%20of%20these%20cells%20in%20the%20above%20code%3F%3CBR%20%2F%3E%3CBR%20%2F%3EQ2%3A%20Now%20the%20problem%20I%20have%20is%20any%20whole%20number%20pasted%20from%20other%20excels%20or%20non-excel%20applications%20clearing%20my%20formatting%20which%20I%20would%20like%20to%20completely%20disable.%3CBR%20%2F%3EI%20want%20to%20keep%20the%20formatting%20of%20the%20cells%20intact.%3CBR%20%2F%3E%3CBR%20%2F%3EFor%20this%20I%20have%20disabled%20(Control%20%2B%20C%2C%20X%2C%20V)%20from%20other%20excels%20and%20non%20excel%20applications%20to%20my%20working%20excel%20with%20the%20codes%20I%20have%20mentioned%20in%20the%20bottom%3CBR%20%2F%3Eand%20disabled%20right%20click%20cut%2C%20copy%20and%20pasting%20from%20excel%20to%20excel%20as%20well%3CBR%20%2F%3Ebut%20right%20click%20pasting%20is%20still%20happening%20from%20non%20excel%20applications%20to%20my%20working%20excel%3CBR%20%2F%3Eso%20when%20I%20right%20click%20it%20is%20giving%20options%20of%20Keep%20Source%20Formatting%20%26amp%3B%20Match%20Destination%20Formatting%3CBR%20%2F%3Ewhen%20selected%20Keep%20Source%20Formatting%20it%20is%20also%20clearing%20formatting%20and%20locking%20that%20particular%20cell.%3CBR%20%2F%3E%3CBR%20%2F%3EI%20wanted%20to%20disable%20this%20option%20of%20(Right%20Click%20Pasting%20from%20non%20excel%20applications)%20as%20well.%3CBR%20%2F%3E%3CBR%20%2F%3EThank%20you%20for%20all%20your%20help!%20%3CLI-EMOJI%20id%3D%22lia_slightly-smiling-face%22%20title%3D%22%3Aslightly_smiling_face%3A%22%3E%3C%2FLI-EMOJI%3E%3CBR%20%2F%3E%3CBR%20%2F%3EPlease%20see%20the%20below%20codes%20which%20I%20have%20tried%20to%20disable%20cut%2C%20copy%20and%20paste%3A%3CBR%20%2F%3E%3CBR%20%2F%3ECode1%3A%3CBR%20%2F%3E%3CBR%20%2F%3E'Disable%20Cut%2C%20Copy%2C%20Paste%20%26amp%3B%20CellDragAndDrop%3CBR%20%2F%3EPrivate%20Sub%20Workbook_Activate()%3CBR%20%2F%3EApplication.CutCopyMode%20%3D%20False%3CBR%20%2F%3EApplication.OnKey%20%22%5Ec%22%2C%20%22%22%3CBR%20%2F%3EApplication.OnKey%20%22%5Ev%22%2C%20%22%22%3CBR%20%2F%3EApplication.OnKey%20%22%5Ex%22%2C%20%22%22%3CBR%20%2F%3EApplication.CellDragAndDrop%20%3D%20False%3CBR%20%2F%3EEnd%20Sub%3CBR%20%2F%3E%3CBR%20%2F%3EPrivate%20Sub%20Workbook_Deactivate()%3CBR%20%2F%3EApplication.CellDragAndDrop%20%3D%20True%3CBR%20%2F%3EApplication.OnKey%20%22%5Ec%22%3CBR%20%2F%3EApplication.OnKey%20%22%5Ev%22%3CBR%20%2F%3EApplication.OnKey%20%22%5Ex%22%3CBR%20%2F%3EApplication.CutCopyMode%20%3D%20False%3CBR%20%2F%3EEnd%20Sub%3CBR%20%2F%3E%3CBR%20%2F%3EPrivate%20Sub%20Workbook_WindowActivate(ByVal%20Wn%20As%20Window)%3CBR%20%2F%3EApplication.CutCopyMode%20%3D%20False%3CBR%20%2F%3EApplication.OnKey%20%22%5Ec%22%2C%20%22%22%3CBR%20%2F%3EApplication.OnKey%20%22%5Ev%22%2C%20%22%22%3CBR%20%2F%3EApplication.OnKey%20%22%5Ex%22%2C%20%22%22%3CBR%20%2F%3EApplication.CellDragAndDrop%20%3D%20False%3CBR%20%2F%3EEnd%20Sub%3CBR%20%2F%3E%3CBR%20%2F%3EPrivate%20Sub%20Workbook_WindowDeactivate(ByVal%20Wn%20As%20Window)%3CBR%20%2F%3EApplication.CellDragAndDrop%20%3D%20True%3CBR%20%2F%3EApplication.OnKey%20%22%5Ec%22%3CBR%20%2F%3EApplication.OnKey%20%22%5Ev%22%3CBR%20%2F%3EApplication.OnKey%20%22%5Ex%22%3CBR%20%2F%3EApplication.CutCopyMode%20%3D%20False%3CBR%20%2F%3EEnd%20Sub%3CBR%20%2F%3E%3CBR%20%2F%3EPrivate%20Sub%20Workbook_SheetSelectionChange(ByVal%20Sh%20As%20Object%2C%20ByVal%20Target%20As%20Range)%3CBR%20%2F%3EApplication.CutCopyMode%20%3D%20False%3CBR%20%2F%3EEnd%20Sub%3CBR%20%2F%3E%3CBR%20%2F%3EPrivate%20Sub%20Workbook_SheetActivate(ByVal%20Sh%20As%20Object)%3CBR%20%2F%3EApplication.OnKey%20%22%5Ec%22%2C%20%22%22%3CBR%20%2F%3EApplication.OnKey%20%22%5Ev%22%2C%20%22%22%3CBR%20%2F%3EApplication.OnKey%20%22%5Ex%22%2C%20%22%22%3CBR%20%2F%3EApplication.CellDragAndDrop%20%3D%20False%3CBR%20%2F%3EApplication.CutCopyMode%20%3D%20False%3CBR%20%2F%3EEnd%20Sub%3CBR%20%2F%3E%3CBR%20%2F%3EPrivate%20Sub%20Workbook_SheetDeactivate(ByVal%20Sh%20As%20Object)%3CBR%20%2F%3EApplication.CutCopyMode%20%3D%20False%3CBR%20%2F%3EEnd%20Sub%3CBR%20%2F%3E%3CBR%20%2F%3ECode2%3A%3CBR%20%2F%3E%3CBR%20%2F%3E'***%20In%20a%20standard%20module%20***%3CBR%20%2F%3EOption%20Explicit%3CBR%20%2F%3E%3CBR%20%2F%3ESub%20ToggleCutCopyAndPaste(Allow%20As%20Boolean)%3CBR%20%2F%3E'Activate%2Fdeactivate%20cut%2C%20copy%2C%20paste%20and%20pastespecial%20menu%20items%3CBR%20%2F%3ECall%20EnableMenuItem(21%2C%20Allow)%20'%20cut%3CBR%20%2F%3ECall%20EnableMenuItem(19%2C%20Allow)%20'%20copy%3CBR%20%2F%3ECall%20EnableMenuItem(22%2C%20Allow)%20'%20paste%3CBR%20%2F%3ECall%20EnableMenuItem(755%2C%20Allow)%20'%20pastespecial%3CBR%20%2F%3E%3CBR%20%2F%3E'Activate%2Fdeactivate%20drag%20and%20drop%20ability%3CBR%20%2F%3EApplication.CellDragAndDrop%20%3D%20Allow%3CBR%20%2F%3E%3CBR%20%2F%3E'Activate%2Fdeactivate%20cut%2C%20copy%2C%20paste%20and%20pastespecial%20shortcut%20keys%3CBR%20%2F%3EWith%20Application%3CBR%20%2F%3ESelect%20Case%20Allow%3CBR%20%2F%3ECase%20Is%20%3D%20False%3CBR%20%2F%3E.OnKey%20%22%5Ec%22%2C%20%22CutCopyPasteDisabled%22%3CBR%20%2F%3E.OnKey%20%22%5Ev%22%2C%20%22CutCopyPasteDisabled%22%3CBR%20%2F%3E.OnKey%20%22%5Ex%22%2C%20%22CutCopyPasteDisabled%22%3CBR%20%2F%3E.OnKey%20%22%2B%7BDEL%7D%22%2C%20%22CutCopyPasteDisabled%22%3CBR%20%2F%3E.OnKey%20%22%5E%7BINSERT%7D%22%2C%20%22CutCopyPasteDisabled%22%3CBR%20%2F%3ECase%20Is%20%3D%20True%3CBR%20%2F%3E.OnKey%20%22%5Ec%22%3CBR%20%2F%3E.OnKey%20%22%5Ev%22%3CBR%20%2F%3E.OnKey%20%22%5Ex%22%3CBR%20%2F%3E.OnKey%20%22%2B%7BDEL%7D%22%3CBR%20%2F%3E.OnKey%20%22%5E%7BINSERT%7D%22%3CBR%20%2F%3EEnd%20Select%3CBR%20%2F%3EEnd%20With%3CBR%20%2F%3EEnd%20Sub%3CBR%20%2F%3E%3CBR%20%2F%3ESub%20EnableMenuItem(ctlId%20As%20Integer%2C%20Enabled%20As%20Boolean)%3CBR%20%2F%3E'Activate%2FDeactivate%20specific%20menu%20item%3CBR%20%2F%3EDim%20cBar%20As%20CommandBar%3CBR%20%2F%3EDim%20cBarCtrl%20As%20CommandBarControl%3CBR%20%2F%3EFor%20Each%20cBar%20In%20Application.CommandBars%3CBR%20%2F%3EIf%20cBar.Name%20%26lt%3B%26gt%3B%20%22Clipboard%22%20Then%3CBR%20%2F%3ESet%20cBarCtrl%20%3D%20cBar.FindControl(ID%3A%3DctlId%2C%20recursive%3A%3DTrue)%3CBR%20%2F%3EIf%20Not%20cBarCtrl%20Is%20Nothing%20Then%20cBarCtrl.Enabled%20%3D%20Enabled%3CBR%20%2F%3EEnd%20If%3CBR%20%2F%3ENext%3CBR%20%2F%3EEnd%20Sub%3CBR%20%2F%3E%3CBR%20%2F%3ESub%20CutCopyPasteDisabled()%3CBR%20%2F%3E'Inform%20user%20that%20the%20functions%20have%20been%20disabled%3CBR%20%2F%3EMsgBox%20%22Sorry!%20Cutting%2C%20copying%20and%20pasting%20have%20been%20disabled%20in%20this%20workbook!%22%3CBR%20%2F%3EEnd%20Sub%3CBR%20%2F%3E%3CBR%20%2F%3E'***%20In%20the%20ThisWorkbook%20Module%20***%3CBR%20%2F%3EOption%20Explicit%3CBR%20%2F%3E%3CBR%20%2F%3EPrivate%20Sub%20Workbook_Activate()%3CBR%20%2F%3ECall%20ToggleCutCopyAndPaste(False)%3CBR%20%2F%3EEnd%20Sub%3CBR%20%2F%3E%3CBR%20%2F%3EPrivate%20Sub%20Workbook_BeforeClose(Cancel%20As%20Boolean)%3CBR%20%2F%3ECall%20ToggleCutCopyAndPaste(True)%3CBR%20%2F%3EEnd%20Sub%3CBR%20%2F%3E%3CBR%20%2F%3EPrivate%20Sub%20Workbook_Deactivate()%3CBR%20%2F%3ECall%20ToggleCutCopyAndPaste(True)%3CBR%20%2F%3EEnd%20Sub%3CBR%20%2F%3E%3CBR%20%2F%3EPrivate%20Sub%20Workbook_Open()%3CBR%20%2F%3ECall%20ToggleCutCopyAndPaste(False)%3CBR%20%2F%3EEnd%20Sub%3C%2FLINGO-BODY%3E
Occasional Contributor

Hope someone can help me on this.

 

I have 3 cells(A1,A2,A3) for which I want only Whole Numbers like 1,2,3 and do not want decimals like 0.1 or 0.5 and neither want alpha chars so I have set Data Validation for these cells to Whole Number. This seems to work fine when I try to enter any non whole number values manually it throws an error and accepts only whole numbers so till here this is good. But when I copy from any other excel or non excel application and paste in these cells it accepts the values and let it paste ignoring the data validation settings. So I added the below code to restrict it to only numbers but this code is allowing decimals as well since the funtion is IsNumeric and blocking only alpha chars. Is there any function which allows only Whole Numbers.

 

'Only numeric values
Const CELL_ADDRESS = "$A$1:$A$3" 'change range
If Not Application.Intersect(Target, Range(CELL_ADDRESS)) Is Nothing Then
If Not Int(Target.Value) Then
MsgBox "You must enter only numeric values", vbCritical, "Invalid Input"
Target.Value = vbNullString
End If
End If

End Sub

6 Replies
best response confirmed by Abdullah_Shurjeel (Occasional Contributor)
Solution

@Abdullah_Shurjeel 

Try this:

 

Private Sub Worksheet_Change(ByVal Target As Range)
    'Only numeric values
    Const CELL_ADDRESS = "A1:A3" 'change range
    Dim rng As Range
    Dim f As Boolean
    If Not Intersect(Target, Range(CELL_ADDRESS)) Is Nothing Then
        For Each rng In Intersect(Target, Range(CELL_ADDRESS))
            If Not IsNumeric(rng.Value) Then
                f = True
            ElseIf Not rng.Value = Int(rng.Value) Then
                f = True
            End If
            If f Then
                MsgBox "You must enter only whole numbers!", vbCritical, "Invalid Input"
                Application.EnableEvents = False
                Application.Undo
                Application.EnableEvents = True
                Exit For
            End If
        Next rng
    End If
End Sub
TRIM removes the digits after the decimal point.

Matrix formula:
= SUM (TRIM (A1: A3))

Additional Formulas:
=INT(A1)
=TRUNC(A1)
=ROUND(A1,0)

Hope I was able to help you with this info.

Nikolino
I know I don't know anything (Socrates)
This is great. Appreciate your quick response.

I have tested the code, it is accepting whole numbers only even when pasted from other excels or non-excel applications.

I have 2 questions here:

Q1: For our sample code we have range of cells from A1 to A3. Suppose I have cells like D8, G10, L9 how do I give input of these cells in the above code?

Q2: Now the problem I have is any whole number pasted from other excels or non-excel applications clearing my formatting which I would like to completely disable.
I want to keep the formatting of the cells intact.

For this I have disabled (Control + C, X, V) from other excels and non excel applications to my working excel with the codes I have mentioned in the bottom
and disabled right click cut, copy and pasting from excel to excel as well
but right click pasting is still happening from non excel applications to my working excel
so when I right click it is giving options of Keep Source Formatting & Match Destination Formatting
when selected Keep Source Formatting it is also clearing formatting and locking that particular cell.

I wanted to disable this option of (Right Click Pasting from non excel applications) as well.

Thank you for all your help!

Please see the below codes which I have tried to disable cut, copy and paste:

Code1:

'Disable Cut, Copy, Paste & CellDragAndDrop
Private Sub Workbook_Activate()
Application.CutCopyMode = False
Application.OnKey "^c", ""
Application.OnKey "^v", ""
Application.OnKey "^x", ""
Application.CellDragAndDrop = False
End Sub

Private Sub Workbook_Deactivate()
Application.CellDragAndDrop = True
Application.OnKey "^c"
Application.OnKey "^v"
Application.OnKey "^x"
Application.CutCopyMode = False
End Sub

Private Sub Workbook_WindowActivate(ByVal Wn As Window)
Application.CutCopyMode = False
Application.OnKey "^c", ""
Application.OnKey "^v", ""
Application.OnKey "^x", ""
Application.CellDragAndDrop = False
End Sub

Private Sub Workbook_WindowDeactivate(ByVal Wn As Window)
Application.CellDragAndDrop = True
Application.OnKey "^c"
Application.OnKey "^v"
Application.OnKey "^x"
Application.CutCopyMode = False
End Sub

Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
Application.CutCopyMode = False
End Sub

Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Application.OnKey "^c", ""
Application.OnKey "^v", ""
Application.OnKey "^x", ""
Application.CellDragAndDrop = False
Application.CutCopyMode = False
End Sub

Private Sub Workbook_SheetDeactivate(ByVal Sh As Object)
Application.CutCopyMode = False
End Sub

Code2:

'*** In a standard module ***
Option Explicit

Sub ToggleCutCopyAndPaste(Allow As Boolean)
'Activate/deactivate cut, copy, paste and pastespecial menu items
Call EnableMenuItem(21, Allow) ' cut
Call EnableMenuItem(19, Allow) ' copy
Call EnableMenuItem(22, Allow) ' paste
Call EnableMenuItem(755, Allow) ' pastespecial

'Activate/deactivate drag and drop ability
Application.CellDragAndDrop = Allow

'Activate/deactivate cut, copy, paste and pastespecial shortcut keys
With Application
Select Case Allow
Case Is = False
.OnKey "^c", "CutCopyPasteDisabled"
.OnKey "^v", "CutCopyPasteDisabled"
.OnKey "^x", "CutCopyPasteDisabled"
.OnKey "+{DEL}", "CutCopyPasteDisabled"
.OnKey "^{INSERT}", "CutCopyPasteDisabled"
Case Is = True
.OnKey "^c"
.OnKey "^v"
.OnKey "^x"
.OnKey "+{DEL}"
.OnKey "^{INSERT}"
End Select
End With
End Sub

Sub EnableMenuItem(ctlId As Integer, Enabled As Boolean)
'Activate/Deactivate specific menu item
Dim cBar As CommandBar
Dim cBarCtrl As CommandBarControl
For Each cBar In Application.CommandBars
If cBar.Name <> "Clipboard" Then
Set cBarCtrl = cBar.FindControl(ID:=ctlId, recursive:=True)
If Not cBarCtrl Is Nothing Then cBarCtrl.Enabled = Enabled
End If
Next
End Sub

Sub CutCopyPasteDisabled()
'Inform user that the functions have been disabled
MsgBox "Sorry! Cutting, copying and pasting have been disabled in this workbook!"
End Sub

'*** In the ThisWorkbook Module ***
Option Explicit

Private Sub Workbook_Activate()
Call ToggleCutCopyAndPaste(False)
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Call ToggleCutCopyAndPaste(True)
End Sub

Private Sub Workbook_Deactivate()
Call ToggleCutCopyAndPaste(True)
End Sub

Private Sub Workbook_Open()
Call ToggleCutCopyAndPaste(False)
End Sub

@Abdullah_Shurjeel 

You could use

 

Const CELL_ADDRESS = "D8,G10,L9"

 

I fear it will be very difficult to make it work 100% the way you want. I recommend instructing users never to use Paste, and only use Paste Values.

To make it easier, you could assign Ctrl+V (^V) to a macro that pastes values only:

 

Sub PasteValuesOnly()
    On Error Resume Next
    Selection.PasteSpecial Paste:=xlPasteValues
End Sub

 

Thank you Hans!

Cell Address is working.

You are right about instructing users to never use Past and only use Paste Values but you know by mistake if they do so that will lock the cell and change the cell to the source formatting while pasting.

So after adding pasting values code, the pasting from non-excel applications to excel still gives right click pasting options of source formatting which I wanted to completely disable.
Thanks Nikolino for the response.
The formulas are helpful for removal of decimal points.