Run a macro automatically when there is a data in a certain Cell

festiki

New Member
Joined
Nov 6, 2013
Messages
7
Hello,

I don't know how to use a macro. I am more on a formula type of guy. Can you please help me? I have a macro in place in my file but I need it to run automatically when a data is encoded or paste in a certain Cell. I have made the macro using the record button. For it to work is for me to manually run it.

Sub moving()
'
' moving Macro
'
'
Range("A4:D4").Select
Application.CutCopyMode = False
Selection.Copy
Range("A8").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("Table1").Select
Application.CutCopyMode = False
Selection.Copy
Range("A9").Select
ActiveSheet.Paste
Range("A8:D8").Select
Selection.ClearContents
Range("B4:D4").Select
Selection.ClearContents
End Sub

I really would appreciate your help. Pardon my English.

Thanks,

Kirby
 
Last edited:

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Why do you say:
"have a macro in place in my file but I need it to run automatically when a data is encoded or paste in a certain Cell

Why do you not tell us what cell??

We need exact details:

Here is a script which will do what you want when you enter data into range ("A1")

It's interesting you copying values from one range and pasting in another range but then clearing the same range.


This is an auto sheet event script
Your Workbook must be Macro enabled
To install this code:
Right-click on the sheet tab
Select View Code from the pop-up context menu
Paste the code in the VBA edit window

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("A1")) Is Nothing Then
If Target.Cells.Count > 1 Or IsEmpty(Target) Then Exit Sub
Range("A4:D4").Copy Range("A8")
Range("Table1").Copy Range("A9")
Range("A8:D8").ClearContents
Range("B4:D4").ClearContents
End If
End Sub
 
Upvote 0
Sorry about that. It's in Cell D4. The Code you have given to me works perfectly. Thank you very much for your help. The only problem I have when I copy paste a data into the cell, the Macro would not work.
 
Last edited:
Upvote 0
Well I think you can see the ideal. I really do not understand what your doing. Your wanting to change a value in D4 then copy A4 to D4 and paste into A9 then clear the same ranges. But I think you see the ideal. Maybe you can modify the script to do what you want. When I use A1 and paste in data it works. But when your wanting to copy data into the same range your wanting to clear i'm not sure how that would work.Thank you very much for your help. The only problem I have when I copy paste a data into the cell, the Macro would not work.[/QUOTE]
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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