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

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
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,223,896
Messages
6,175,260
Members
452,627
Latest member
KitkatToby

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