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!
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Give me a example of what you might want to do.

Like maybe Select Range("A1") and fill down 20 cells.
 
Upvote 0
Yes, that would be a perfect example.

I have made a template for my students that is fairly complex and it involves a table of 40 samples with alternating colors at each row, but also I have applied conditional formatting to highlight rows based on either errors or certain values entered. But they get lazy and instead of typing sample names, they do a lot of copy/pasting or dragging/filling and mess up with the formatting. I was able to "fix" the copy/pasting problem through a VBA code I found online at this link below (comment #27154 at the comments section at the bottom), but so far I haven't been able to prevent the dragging/filling issue, so I'm hoping you have a nice trick for that :biggrin:

 
Upvote 0
Keeping users from doing things you do not want them to do is always a big problem and probable impossible to stop.
My first computer Job was rewriting formulas users had deleted.

My only real answer was to keep backups of my files off Site.
And then at least not have to rewrite 40 formulas they had written over. 😎
 
Upvote 0
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!
Here is an example:
VBA Code:
    Range("I12").AutoFill Destination:=Range("I12:I15"), Type:=xlFillValues
 
Upvote 0
I just tested it like this by putting the code in my Sheet1: Range("E3").AutoFill Destination:=Range("E3:E42"), Type:=xlFillValues

And I get an error just by even clicking anywhere in the sheet: "Compile error: Invalid outside procedure", and the range "E3:E42" is highlighted in the editor.

Any idea what could be causing this?
 
Last edited:
Upvote 0
Can you post your code so I can try and duplicate your problem?
 
Upvote 0
I only have the following two codes:

in Sheet1:

Range("E3").AutoFill Destination:=Range("E3:E42"), Type:=xlFillValues

in ThisWorkbook:

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
This script works for me:
Range("E3").AutoFill Destination:=Range("E3:E42"), Type:=xlFillValues

But your other script in the sheet:

Is Probable causing the problem.
What is it supposed to be doing?
 
Upvote 0

Forum statistics

Threads
1,223,952
Messages
6,175,596
Members
452,657
Latest member
giadungthienduyen

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