If values in Column L = specific text, insert specific text into a value in Column W and todays date in X

Hi All,
Below Macro updates the column W with a text "Closed" if Column L is =  'Y' . I also like to add sysdate in column X . Any help would be wonderful.

Private Sub UpdateColumnW()
    Dim x As Long
    For x = 1 To 65536
        If InStr(1, Sheet1.Range("$L$" & x), "Y") > 0 Then
            Sheet1.Range("$W$" & x) = Sheet1.Range("$W$" & x) & "Closed"
        End If
    Next
End Sub

Thanks.
Milind AgarwalAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
You may try something like this.....

The following code assumes that you want to run this code on Sheet1 and row1 is header row. The code will insert the sysdate in the format mm/dd/yyyy hh:mm:ss You can tweak the code as per your requirement.

Sub UpdateColumnsWAndX()
Dim ws As Worksheet
Dim lr As Long
Dim cell As Range
Set ws = Sheet1
lr = ws.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
ws.AutoFilterMode = 0
With ws.Rows(1)
   .AutoFilter field:=12, Criteria1:="y"
   If ws.Range("W1:W" & lr).SpecialCells(xlCellTypeVisible).Cells.Count > 1 Then
      For Each cell In ws.Range("W2:W" & lr).SpecialCells(xlCellTypeVisible)
         cell = cell & " Closed"
         cell.Offset(0, 1) = Format(Now, "mm/dd/yyyy hh:mm:ss")
      Next cell
      
   End If
   .AutoFilter
End With
MsgBox "Done!", vbInformation
End Sub

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Milind AgarwalAuthor Commented:
Works like dream!
Milind AgarwalAuthor Commented:
Thanks Sktneer
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
You're welcome Milind! Glad I could help.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.