Automating Inputting to a Range

MattNewby

Board Regular
Joined
Dec 15, 2009
Messages
155
Hi,

I have the following code that I use and it works fine for a sigle cell, but I want to adapt this so that it will add todays date to a range that I have selected.

The code I think I need to change is in pink, just not sure how to make an equivalent of active range.


Please advise

Matt :banghead::banghead::banghead:

Code:

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)

With Worksheets(1).Range("C:C")
.Value = .Value
End With



End Sub

Private Sub Workbook_SheetBeforeDoubleClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean)

ActiveCell = DateValue(Now)

End Sub
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Try

Code:
Private Sub Workbook_SheetBeforeDoubleClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean)
Dim c As Range
Cancel = True
For Each c In Target
    c.Value = Date
Next c
End Sub
 
Upvote 0
For a multi-cell selection, you'll need to use the BeforeRightClick event. One can not double click on a multi-cell range.
 
Upvote 0
Hi,

Thanks for that, but it does not work. It just put the date value in the last cell of the range I have selected.

Also in the code what does 'target' refer to???

Thanks

Matt
 
Upvote 0

Forum statistics

Threads
1,224,585
Messages
6,179,704
Members
452,938
Latest member
babeneker

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