Is there any way that 'filling' can be restricted to values only and not formatting, perhaps through VBA?

Rnkhch

Well-known Member
Joined
Apr 28, 2018
Messages
578
Office Version
  1. 365
Platform
  1. Windows
Hello,

I know that it is possible to right-click and drag and then select 'fill without formatting', but is there any formatting changes can be disabled for dragging/filling, perhaps through a VBA code? :biggrin:

Thanks for any input!
 
This script is supposed to do what??

VBA Code:
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
On Error Resume Next
If Not Application.CutCopyMode = False Then
Target.PasteSpecial xlPasteValues
Application.CutCopyMode = True
End If
End Sub
 
Upvote 0

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
@Rnkhch Is the first code your complete code? then if it is it needs to be in a Sub like you have posted with the 2nd code or a regular sub, if it is not your complete code then post the complete code please
 
Upvote 0
@ My Answer Is This: That script allows the users to do just a single click at the destination and paste the values of anything that was copied. So it prevents formatting transfer during copy/paste. You can see the details here (comment #27154 at the comments section at the bottom):



@ MARK858: The first code is just that 1 line that was suggested by JohnnyL at post #6
 
Upvote 0
Since now we have others here helping you, I will move on to help someone else who may need help.
 
Upvote 0
Incidentally, I tried the same 1 line of code in a new blank workbook and I highlighted cell E3 and dragged it down, and the highlight still carried over, so as far as I can see that one line of code on its own doesn't do anything? Am I missing something?


2022-07-30 (1).png
 
Upvote 0
Oh I see, so it needs to be in a Sub? 🤦‍♂️ Could you please help me with that? I'm a newb at VBA and not sure how to get the syntax perfectly right for the Sub 😅 Thank you!
 
Upvote 0
How are you intending to run the code via a button / Alt+F8 or triggered by some action on the worksheet? if the latter what action?
 
Upvote 0
I would say triggred by acion, which would mean when the user is dragging any cell in the range of E3:E42
 
Upvote 0
dragging any cell in the range of E3:E42
If they were dragging the cell then they wouldn't need that macro

The code below runs if they double click any single cell in the range E3:E42

VBA Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    If Not Intersect(Target, Range("E3:E42")) Is Nothing And Target.CountLarge = 1 Then
        Application.EnableEvents = False
        Range("E3").AutoFill Destination:=Range("E3:E42"), Type:=xlFillValues
        Application.EnableEvents = True
    End If
End Sub

The code goes in the Worksheet module
 
Upvote 0

Forum statistics

Threads
1,223,277
Messages
6,171,148
Members
452,382
Latest member
RonChand

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