VBA SelectionChange on specific cells, copy into another sheet

SamAnnElizabeth

New Member
Joined
Mar 15, 2013
Messages
34
I'm new to writing VBA but I think I'm close to something. I want a macro that will run if a cell is changed in the range F10:F31. I want it to put in a different sheet the text of the cell address " Updated On " and the date. I think I'm close to something, but this isn't running.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target = "$F$10:$F:$31" Then
Sheets("List1").Select
Range(D1).End(xlDown).Offset(1, 0).Select
ActiveCell = Cell & " Updated On " & Date
End If
End Sub

So what I would want is that if F26 was updated, D2 would read "F26 Updated On 4/10/13". (I have a header in D1.) If F14 was changed next, D3 would read "F14 Updated On 4/10/13". I have the sub saved within the sheet where the F10:F31 is located. Any help?
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Place this code in the worksheet code module.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Intersect(Target, Range("F10:F31")) Is Nothing Then Exit Sub
    Sheets("List1").Cells(Rows.Count, "D").End(xlUp).Offset(1, 0).Value = Target.Address(0,0) & " was updated on " & Date
End Sub
 
Upvote 0
I'm glad it worked out although I'm not sure why you needed an 'End If' line. The 'If ... Then' statement is on one line and therefore it shouldn't need an 'End If".
 
Upvote 0
Ah, my own fault. I put "End Sub" on the next line.

Maybe you can help me with something else. Is there a way to return the text of a box four columns left of the active cell instead of the cell address of the active cell? I tried this but it didn't work:


Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("F10:F31")) Is Nothing Then Exit Sub
Sheets("List1").Cells(Rows.Count, "D").End(xlUp).Offset(1, 0).Value = Target.Text(0,-4) & " was updated on " & Date
End Sub
 
Upvote 0
Try this:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Intersect(Target, Range("F10:F31")) Is Nothing Then Exit Sub
    Sheets("List1").Cells(Rows.Count, "D").End(xlUp).Offset(1, 0).Value = Target.Offset(0,-4).Value & " was updated on " & Date
End Sub
 
Upvote 0
Sure. Assuming by "4 columns to the left", you mean column B, just change:
Target.Text(0,-4)
to
Target.Offset(0,-4)

Hope it helps.
 
Upvote 0

Forum statistics

Threads
1,215,639
Messages
6,125,971
Members
449,276
Latest member
surendra75

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