![]() |
![]() |
![]() |
|||||
![]() |
![]() |
![]() |
![]() |
![]() |
|||
| Welcome
to Tech Support Forum home to more then 136,000 problems solved. Issues
have included: Spyware, Malware, Virus Issues, Windows, Microsoft,
Linux, Networking, Security, Hardware, and Gaming Getting your
problem solved is as easy as: 1. Registering for a free account 2. Asking your question 3. Receiving an answer Registered members: * See fewer ads. * And much more..
|
| Want to know how to post a question? click here | Having problems with spyware and pop-ups? First Steps |
|
|||||||
| Microsoft Office support MS Office support forum |
![]() |
|
|
LinkBack | Thread Tools |
|
|
#1 (permalink) |
|
Registered User
Join Date: Feb 2009
Posts: 4
OS: vista
|
For Each Cell in Selection
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub If Not Intersect(Target, Range("ar1:ar30000")) Is Nothing Then ' With Target(1, 10) .Value = Date End With End If End Sub This code above does ALMOST exactly what I want it to do. The problem arises when I select multiple cells at once. Then it only looks at the first cell in the selection. Below is my attempt to tell the macro to do it for every cell in the selection and put the date in the field ten cells to the right. For example. if cell A1 = Dog and I highlight A1 and change that cell, cell K1 should say the date if cell A1 = dog and cell A2 equals Cat and I select both cell A1 and A2, and then hit the delete button, I want cell K1 to say the date and at the same time change cell L1 to also say the date. Below is my poor attempt to make this work. Please Help. Private Sub Worksheet_Change(ByVal CurCell As Range) If Target.Cells.Count > 100 Then Exit Sub For Each CurCell In Selection If Not Intersect(CurCell, Range("q5:at1000")) Is Nothing Then With CurCell(1001, 1) .Value = Date Next CurCell End With End If End Sub I want to be able to run this code for multimple cells that are selected at once. I cant get the code to work. Please Help |
|
|
|
| Important Information |
|
Join the #1 Tech Support Forum Today - It's Totally Free!
TechSupportForum.com is a leading support website for your computer needs. We offer free, friendly and personalized computer support. Why pay to have your computer fixed when you can do it for free. Join TechSupportforum.com Today - Click Here |
|
|
#2 (permalink) |
|
Registered User
Join Date: May 2008
Location: Baltimore, Maryland
Posts: 160
OS: Windows XP SP3
|
Re: For Each Cell in Selection
The following example may be helpful. Consider the following code:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim CurCell As Range
If Target.Cells.Count > 100 Then
Exit Sub
End If
Application.EnableEvents = False
For Each CurCell In Target
If Not Intersect(CurCell, Range("A1:B1000")) Is Nothing Then
CurCell.Offset(0, 9).Value = Date
End If
Next CurCell
Application.EnableEvents = True
End Sub
If you wish to have the range where the dates appear transposed, so that if, for example, the selection is in one column and multiple rows (A1:A2) but the dates are in one row and multiple columns (J1:K1), it will be necessary to make modifications based on the line CurCell.Offset(0, 9).Value = Date Last edited by David M58; 03-05-2009 at 05:12 PM. |
|
|
|
![]() |
| Thread Tools | |
|
|