How to automatically fill text if text in another cell is changed or added

SunnyAlv

Active Member
Joined
May 23, 2023
Messages
337
Office Version
  1. 365
Platform
  1. Windows
I am a beginner when it comes to using VBA EXCEL, i hope u can help me

VBA Question

please see image below

1703233587075.png



I just want to know how to fill the day (TODAY) in each cell in column "A" if :

1. Columns C - F have been filled with text but have changed (in whatever form the essence has changed)

2. every time a new item is added to the last row


***adding the date (TODAY) according to the row the item was changed/new item added


Thank U :)
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
See if the following gives you what you want. As it is worksheet event code, you add it by right-clicking on the sheet tab, select View Code & place the code in the window that appears on the right of the screen. You'll need to save the file as macro-enabled or binary format thereafter.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Row > 1 And Not Intersect(Range("C:F"), Target) Is Nothing Then
        Application.EnableEvents = False
        Cells(Target.Row, 1) = Date
        End If
    Application.EnableEvents = True
End Sub
 
Upvote 0
See if the following gives you what you want. As it is worksheet event code, you add it by right-clicking on the sheet tab, select View Code & place the code in the window that appears on the right of the screen. You'll need to save the file as macro-enabled or binary format thereafter.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Row > 1 And Not Intersect(Range("C:F"), Target) Is Nothing Then
        Application.EnableEvents = False
        Cells(Target.Row, 1) = Date
        End If
    Application.EnableEvents = True
End Sub
Chanced upon this thread, and looks useful / similar to my use case.

I'll write down my use case, can you let me know if the above VBA code you provided works? (i believe a few tweaks here and there may be needed...)

I need to autofill cells in column D as 'NZD' once cells in column C are filled in / selected from dropdown menu.
1721793209806.png
 
Upvote 0
I need to autofill cells in column D as 'NZD' once cells in column C are filled in
Welcome to the MrExcel board!

Try this code instead. It has a bit more built in. If a number is entered in col C then "NZD" will be placed in col D as requested. If a cell in col C has a number deleted, the "NZD" will be removed from col D.
If a number of cells in col C are dealt with at once (eg multiple cells are selected and the values deleted or values entered in multiple cells with Ctrl+Enter or Copy/Paste) then the code will deal with each of the affected rows individually.

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  Dim Changed As Range, c As Range
  
  Set Changed = Intersect(Target, Range("C2:C" & Rows.Count))
  If Not Changed Is Nothing Then
    Application.EnableEvents = False
    For Each c In Changed
      If IsNumeric(c.Value) And Len(c.Value) > 0 Then
        c.Offset(, 1).Value = "NZD"
      Else
        c.Offset(, 1).ClearContents
      End If
    Next c
    Application.EnableEvents = True
  End If
End Sub
 
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