Help with VBA?

mcintoshmc

Active Member
Joined
Aug 10, 2007
Messages
277
I'm using this VBA, and it worked perfectly the first day, but over the weekend I came back to work, and it only works in the cells towards the bottom of the sheet, but not those on the top. I have no idea why it's doing that.

Basically, column O is a notes column. Once I make a change in said column, it enters the date in column Z. I have conditional formatting which will color the entire row.

Can anyone tell me why it is only working in some rows, but not all? The range does say "O:O", so not sure whats happening.


Private Sub Worksheet_Change(ByVal Target As Range)
Dim rInt As Range
Dim rCell As Range
Dim tCell As Range

Set rInt = Intersect(Target, Range("O:O"))
If Not rInt Is Nothing Then
For Each rCell In rInt
Set tCell = rCell.Offset(0, 11)
If IsEmpty(tCell) Then
tCell = Now
tCell.NumberFormat = "mmm d, yyyy hh:mm"
End If
Next
End If
End Sub
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Actually, I see the problem. It will only work if the cell is blank. If the cell has a previous date, it will not enter the new date. Is there a way for this to work when the cell is not blank?
 
Upvote 0
Your code checks is col Z is empty, if it isn't then nothing will happen.
Do you want col Z changed if a value is already there?
 
Upvote 0
Seeing post#2, try
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   Dim rInt As Range
   Dim rCell As Range
   Dim tCell As Range
   
   Set rInt = Intersect(Target, Range("O:O"))
   If Not rInt Is Nothing Then
      For Each rCell In rInt
         With rCell.Offset(0, 11)
            .Value = Now
            .NumberFormat = "mmm d, yyyy hh:mm"
         End With
      Next
   End If
End Sub
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,825
Messages
6,181,190
Members
453,020
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