Macro paste values in current row when text changes

mhay5656

New Member
Joined
May 30, 2017
Messages
7
Hi,
I need a VBA/Macro for disabling lookups in the current row of column D when text changes to "Today" .

For example, I have 100 rows and 5 columns in my sheet, in column 4 (D) if the cell shows "Today" I want the entire rows lookups to be disable or paste values to stop the lookups.
Thank you in advance.
Maureen
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
In order to come up with automated VBA code, we first need to understand exactly how the data is being updated.
How is the text in column D being changed to the word "Today"?
Is something manually entering it?
 
Upvote 0
Right-click on the sheet tab name at the bottom of the screen, select "View Code", and paste this VBA code in the resulting VB Editor window.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    Dim rng As Range
    Dim cell As Range
    Dim r As Long
    
    Set rng = Intersect(Target, Range("D:D"))
    If rng Is Nothing Then Exit Sub
                
    Application.EnableEvents = False
    
    For Each cell In rng
        If cell = "Today" Then
            r = cell.Row
            Rows(r).Copy
            Cells(r, "A").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
                :=False, Transpose:=False
            Application.CutCopyMode = False
        End If
    Next cell
    
    Application.EnableEvents = True
    
End Sub
This code will run automatically, as column D is updated.
 
Upvote 0

Forum statistics

Threads
1,224,819
Messages
6,181,153
Members
453,021
Latest member
Justyna P

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