Copy Formula from Cell 200 of that column into deleted Cell - VB

eli_m

Board Regular
Joined
Jun 2, 2022
Messages
129
Office Version
  1. 365
Platform
  1. Windows
Hi - This site has helped me so much I thought I'd sign up and ask my own question and hopefully help others :)

My question:
What would be the VB code for when I delete data from a cell it then automatically copies the formula that's in cell 200 of that row into the newly deleted cell?

eg.

1. Delete data in cell A1
2. Formula from A200 gets put into cell A1

I also want it to work for all my columns which is A to AR.

Another example:

1. Delete data from F68
2. Formula from F200 populates into F68

Any help would be greatly appreciated!

Thank you in advance
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Hi,
This has been working great but when I paste into a cell that already has a value that ISN'T from cell 200 I get these errors:
Overflow.png



Is there a way to fix this?

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

If Target.CountLarge / Rows.Count = Int(Target.CountLarge / Rows.Count) Then Exit Sub 'Exit code if whole columns are edited

' Copy from Line 200 into deleted cells
  Dim Changed As Range, c As Range
 
  Set Changed = Intersect(Target, Columns("A:AS"))
  If Not Changed Is Nothing Then
    Application.EnableEvents = False
    For Each c In Changed
      If IsEmpty(c.Value) Then Cells(200, c.Column).Copy Destination:=c
    Next c
    Application.EnableEvents = True
  End If

' Ignore Errors with Worksheet Clicks
Dim r As Range: Set r = Range("A2:AS200")
Dim cel As Range

For Each cel In r
  With cel
    .Errors(8).Ignore = True 'Data Validation Error
    .Errors(9).Ignore = True 'Inconsistent Error
    .Errors(6).Ignore = True 'Lock Error
  End With
Next cel

End Sub
 
Upvote 0
when I paste into a cell that already has a value that ISN'T from cell 200 I get these errors:
I have not been able to reproduce that. Can you explain an example of ..
- which cell did you copy?
- what was in that cell?
- which cell did you paste into?
- what was in that cell before you pasted?
- what is in row 200 of the column that you are pasting into?
 
Upvote 0
I have not been able to reproduce that. Can you explain an example of ..
- which cell did you copy?
- what was in that cell?
- which cell did you paste into?
- what was in that cell before you pasted?
- what is in row 200 of the column that you are pasting into?


- which cell did you copy? - Copied text from an email
- what was in that cell? - Cell had a 07/07/2022 in it
- which cell did you paste into? Q53
- what was in that cell before you pasted? Cell had a 07/07/2022 in it
- what is in row 200 of the column that you are pasting into?
Excel Formula:
=IF([@Manufacturer]="Australia","Pre-Book Loan Set","")

Even I now can't replicate it. I've had it happen numerous times when pasting something in. I'll keep an eye on it and report back if it happens again and hopefully they I can replicate it!
 
Upvote 0
What range on the sheet does the whole table containing the 'Manufacturer' column occupy?
What worksheet column is 'Manufacturer' in?
 
Upvote 0
The whole table cannot be just column L as the table must also include (at least) the column that the formula is going into.

What range on the sheet does the whole table containing the 'Manufacturer' column occupy?
 
Upvote 0
Thanks.
So we will just have to wait to see what happens in relation to this:
I'll keep an eye on it and report back if it happens again and hopefully they I can replicate it!
 
Upvote 0
Thanks.
So we will just have to wait to see what happens in relation to this:

I am to replicate the error another way:

Column AH has "DHL: xxxxxxxxx":
1657857019512.png


When I change that to just numbers eg. 326041959578 I get:
1657857064875.png


When I click Debug I get:
1657857095787.png



Full code:
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Application.CutCopyMode = False Then
Application.Calculate
End If
End Sub

' Ignore Errors when Worksheet Activated
Private Sub Worksheet_Activate()

Dim r As Range: Set r = Range("A2:AS200")
Dim cel As Range

For Each cel In r
  With cel
    .Errors(8).Ignore = True 'Data Validation Error
    .Errors(9).Ignore = True 'Inconsistent Error
    .Errors(6).Ignore = True 'Lock Error
  End With
Next cel

End Sub

Private Sub Worksheet_Change(ByVal Target As Range)

If Target.CountLarge / Rows.Count = Int(Target.CountLarge / Rows.Count) Then Exit Sub 'Exit code if whole columns are edited

' Copy from Line 200 into deleted cells
  Dim Changed As Range, c As Range
 
  Set Changed = Intersect(Target, Columns("A:AS"))
  If Not Changed Is Nothing Then
    Application.EnableEvents = False
    For Each c In Changed
      If IsEmpty(c.Value) Then Cells(200, c.Column).Copy Destination:=c
    Next c
    Application.EnableEvents = True
  End If

' Ignore Errors with Worksheet Clicks
Dim r As Range: Set r = Range("A2:AS200")
Dim cel As Range

For Each cel In r
  With cel
    .Errors(8).Ignore = True 'Data Validation Error
    .Errors(9).Ignore = True 'Inconsistent Error
    .Errors(6).Ignore = True 'Lock Error
  End With
Next cel

End Sub
' Auto Refresh Pivot Tables
Private Sub Worksheet_Deactivate()
  ThisWorkbook.RefreshAll

On Error Resume Next

End Sub
 

Attachments

  • 1657856903544.png
    1657856903544.png
    5.9 KB · Views: 2
Upvote 0

Forum statistics

Threads
1,214,839
Messages
6,121,892
Members
449,058
Latest member
Guy Boot

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