Worksheet Change event VB

snap88

New Member
Joined
Jun 20, 2012
Messages
4
This is first time I've used VB since college many years ago.

I'm trying to create a spreadsheet for loging asset use at work.

See below for example
NAME
SCANNER ID
TIME OUT
SCANNER ID
TIME IN

<TBODY>
</TBODY>


I've currently got the sheet set up so when data is input to SCANNER ID a timestamp appears in TIME OUT this works great.

I want to use the same change event idea, so I can book the scanners back in.

The code I have is as follows,

Private Sub Worksheet_Change(ByVal Target As Range)
Dim Cell As Range
For Each Cell In Target
With Cell
If .Column = Range("B:B").Column Then
Cells(.Row, "C").Value = DateValue(Date) & " " & TimeValue(Now())
End If
End With
Next Cell
End Sub

I thought I could just copy this and insert it again with Range / Row Changed, but excel keeps telling me off.

Any help would be great!!!

Chris
 

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)
You can only have one Worksheet_Change per sheet so you'll need to combine them.
 
Upvote 0
Post the code for both of them using code tags

[code]
code goes here
[/code]
 
Upvote 0
Code:
Private Sub Worksheet_Change(ByVal Target As Range)

Dim Cell As Range
For Each Cell In Target
With Cell

If .Column = Range("B:B").Column Then
Cells(.Row, "C").Value = DateValue(Date) & " " & TimeValue(Now())

End If
End With
Next Cell

End Sub

That's what I have so far for the first set of columns.
 
Last edited:
Upvote 0
Try like this

Code:
Private Sub Worksheet_Change(ByVal Target As Range)

Dim Cell As Range
For Each Cell In Target
    With Cell
    
    If .Column = Range("B:B").Column Then
        Cells(.Row, "C").Value = DateValue(Date) & " " & TimeValue(Now())
    ElseIf .Column = Range("D:D").Column Then
        'code here
    End If
    End With
Next Cell

End Sub
 
Upvote 0

Forum statistics

Threads
1,219,162
Messages
6,146,660
Members
450,706
Latest member
LGVBPP

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