Macro question - replacing formula

Kutrenia

New Member
Joined
Dec 31, 2009
Messages
17
I have a spreadsheet where dates are entered in a6:a49 either manually or automatically if cells f6:f49 contains data (names of cities). I'm trying to do a macro that would put the formula =IF(ISBLANK(f6:f49),"",NOW()) in cells a6:a49 if that cell's value is erased/deleted.
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
you can try this

Code:
Sub ReplaceFormula()
Dim MyRng As Range
Dim MyCll As Range
Set MyRng = ActiveSheet.Range("A1:A10")
   For Each MyCll In MyRng
      If MyCll = "" Then
        MyCll.Offset(0, 1) = 0
        Else
        MyCll.Offset(0, 1) = Now()
      End If
   Next MyCll
End Sub
 
Upvote 0
Try using:
Code:
Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
Application.ScreenUpdating = False
Dim ARange As Range
Dim ACell As Range
Set ARange = Range("A1:A20")
For Each ACell In ARange
    If ACell.Offset(0, 5) = "" Then
        ACell = Now()
    End If
Next ACell
Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,692
Messages
6,126,230
Members
449,303
Latest member
grantrob

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