|
-
Feb 13th, 2006, 05:35 AM
#1
Thread Starter
Addicted Member
[RESOLVED] Excel 97: onChange?
I've got the following code in cell d1
(Username() is a function in a module which gets the user's username)
=IF(ISBLANK(A1),"",UserName())
What I want is to set D1 to the user name only when A1 changes from blank to not-blank
At the moment if A1 is non-blank D1 get updated whenever the spreadsheet is opened
So I supose I need a sort of onchange event on A1
How?
Thanks
Another light-hearted post from Guru 
-
Feb 13th, 2006, 09:50 AM
#2
Re: Excel 97: onChange?
You can use the _Change event of the worksheet - checking to see if A1 was the cell being changed. Then based on what change was made to A1 you can either add or remove the formula from cell D1.
VB Code:
Private Sub Worksheet_Change(ByVal Target As Range)
'Only continue if the user is
'changing cell A1
If Target.Address = "$A$1" Then
'If A1 is not blank then add
'the formula to D1
If Target.Value <> "" Then
Range("D1").Formula = "=IF(ISBLANK(A1),"""",UserName())"
'Otherwise remove the formula
Else
Range("D1").Formula =""
End If
End If
End Sub
Last edited by DKenny; Feb 13th, 2006 at 09:56 AM.
Declan
Don't forget to mark your Thread as resolved.
Take a moment to rate posts that you think are helpful 
-
Feb 13th, 2006, 10:00 AM
#3
Thread Starter
Addicted Member
Re: Excel 97: onChange?
O...K...
Thanks for the reply, it looks like we're heading in the right direction
but I wasn't telling the whole truth.
I need to cover the whole column so if A1 changes, D1 gets populated
but also if ANY cell in column A changes the corresponding D cell needs to be set.
Any ideas?
Thanks
Another light-hearted post from Guru 
-
Feb 13th, 2006, 10:04 AM
#4
Re: Excel 97: onChange?
OK
In that case you need to check the Column number of the cell being changed to see if it is column A and then change the formula in the cell 3 to the right of that cell, i.e. in column D.
VB Code:
Private Sub Worksheet_Change(ByVal Target As Range)
'Only continue if the user is
'changing column A
If Target.Column = 1 Then
'If the cell in column A
'is not blank then add
'the formula to the coresponding
'cell in column D
If Target.Value <> "" Then
Target.Offset(0, 3).Formula = "=IF(ISBLANK(A1),"""",UserName())"
'Otherwise remove the formula
Else
Target.Offset(0, 3).Formula = ""
End If
End If
End Sub
Declan
Don't forget to mark your Thread as resolved.
Take a moment to rate posts that you think are helpful 
-
Feb 13th, 2006, 10:16 AM
#5
Thread Starter
Addicted Member
Re: Excel 97: onChange?
Thanks DKenny
I was just working on it myself and came up with this:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 1 Then
If Target.Value <> "" Then
Target.Worksheet.Cells(Target.Row, 4) = UserName()
Else
Target.Worksheet.Cells(Target.Row, 4) = ""
End If
End If
End Sub
Thanks for the help dude!
Another light-hearted post from Guru 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|