473,385 Members | 1,736 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Add today's date to another cell after cell value changes ExcelVBA

63
I am trying to write a procedure so that when data in row AF of Excel is amended then the date the amendment took place is entered into column AM. I thought I would start by trying to get it to work for one cell rather than a range and did the following:


Private Sub Worksheet_Change(ByVal Target As Range)



Application.EnableEvents = False
If (Target.Address = "$AF$7") Then
ActiveCell.Offset(0, 7).Select
ActiveCell.FormulaR1C1 = "today()"

Application.EnableEvents = True

End Sub

This does not error - but it doesn't post the date (or in fact anything!)

Please help!
Nov 10 '11 #1
3 3157
Killer42
8,435 Expert 8TB
The first thing I'd suggest is to put a breakpoint on your If statement and display the value of Target.Address to make sure it matches what you expect.

Secondly, I suspect you may be setting the formula incorrectly. Pretty sure it needs an "=" at the start.

Hm... actually, I'd fix the formula first. Then chase up the address if it still doesn't work.
Dec 15 '11 #2
grego9
63
I ended up sussing this one without using VBA
The values in column AF were the ones that were changing and the ones I wanted to timestamp. I put this formula in AU6.

=IF(ISBLANK(AF6),"",IF(AU6="",NOW(),AU6))

I put this in AV6 (gives the iteration number and the data held):

=IF(AT6<>"",IF(AV6="",0&" - "&AT6,IF(RIGHT(AV6,LEN(AV6)-4)=""&AT6,AV6,MOD(LEFT(AV6,1)+1,10)&" – "&AT6)),"")

This in AW6 (gives the date the event happened
=IF(AT6<>"",IF(AW6="",0&" – "&NOW(),IF(LEFT(AW6,1)=LEFT(AV6,1),AW6,LEFT(AV6,1) &" – "&NOW())),"")

This in AX6 - gives the full timestamp

=IF(AW6<>"",VALUE(RIGHT(AW6,LEN(AW6)-4)),"")


Hope this saves a few hours for some other users!
Dec 15 '11 #3
Killer42
8,435 Expert 8TB
Glad to hear you got it sorted.

And thanks for posting your solution here for posterity. As you said, it could save other people hours trying to figure it out.
Dec 15 '11 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Phil Powell | last post by:
The date field I believe is of type datetime, but I'm sorry I have absolutely no idea how to put today's date into a datetime column using ASP and SQL Server. Folks, I'm a LINUX guy!!! This is a...
5
by: Janet Chapman | last post by:
I am creating a database for a video shop and in the loans table want there to be a field for date taken, with a default value of today. Trying to write =today() as in the help gives an error,...
2
by: Richard | last post by:
I have a textbox and an HtmlInputButton control on a Webform for an Intranet app. When the user clicks the button, it is supposed to add today's date to the textbox using JavaScript on the client...
1
by: TB | last post by:
Hi All: A kind soul provided by with the code for very nice calendar popup, which all in all works fine execpt for one thing: If I pick the current date (i.e. today's date) then the pop-up does...
0
by: TB | last post by:
Hi All: A kind soul provided by with the code for very nice calendar popup, which all in all works fine execpt for one thing: If I pick the current date (i.e. today's date) then the pop-up does...
7
by: joeyej | last post by:
How do I compare today's date with this string (in my inc file) so that I can set an alert if date choice i.e. May 15, 2006 not at least greater than two days from current date? <option...
4
by: Kun | last post by:
i have a form which takes in inputs for a mysql query. one of the inputs is 'date'. normally, a user has to manually enter a date, but i am wondering if there is a way to create a button which...
5
by: M Skabialka | last post by:
I am creating my first Visual Studio project, an inventory database. I have created a form and used written directions to add data from a table to the form using table adapters, data sets, etc. ...
4
by: Holmsey | last post by:
Hi I have to convert am today's date and time (now) to a webservice. The example the web service gives was "1163313527144#" which comes out to 12/31/1969 06:00 PM. How do I convert a date to a 13...
1
by: cptuser | last post by:
Hi, I have a date field on a form. The date in the date field has to be after today's date and not in the past. It also has to be within 30 days from today's date. So if today is 13/04/2007, then...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.