-
Apr 28th, 2020, 12:43 PM
#1
Thread Starter
New Member
Visual Basic Private Sub won't run
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
If Intersect(Target, Range("q:q")) Is Nothing Then
With Target(1, 2)
.Value = Date & " "
.EntireColumn.AutoFit
End Sub
I have found several similar versions of this, but none of them function. I feel like I'm just missing the on switch.
Excel in Office home recently updated. Windows 10 computer.
Bill
-
Apr 28th, 2020, 12:46 PM
#2
Re: Visual Basic Private Sub won't run
Welcome to VBForums
Thread moved from the 'VB.Net' forum to the 'Office Development/VBA' forum.
-
Apr 28th, 2020, 04:17 PM
#3
Re: Visual Basic Private Sub won't run
please describe what you want it to actually do
it would appear that if the cell changed is not in column Q then put the date and a space into the cell in the next column, which does not really make sense to me
if you put a break point on some line in that sub then you can confirm that the event is firing
BUT as there is 2 errors in the code, if it was running a break would occur as soon as the sub fired
the sub MUST be on the code pane for the sheet where the change is to happen
best to use the drop down boxes at the top of the code pane, rather than just paste the procedure onto some code pane
target(1, 2) is the same as target.offset(, 1)
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Apr 29th, 2020, 03:45 AM
#4
Re: Visual Basic Private Sub won't run
As Pete says, a description of what you're trying to accomplish would be helpful.
Having said that, if you fix the errors he mentions, I don't think you'd like the results. If you change a value in column A, it will write a date in column B, same row. That will then write to C, which will write to D, etc. until you get to Q, which is where it will stop. Is that what you want?
-
Apr 29th, 2020, 02:14 PM
#5
Thread Starter
New Member
Re: Visual Basic Private Sub won't run
No. If I place a value in blank cell a I want a date recorded in blank cell b. I have this resolved I finally found a code that worked. The only thing I would like to do now is figure out how to do the exact same thing in a separate place on the sheet with a separate entry. For example, if I put an entry in column k I want a date recorded in column j. I can make that code work just like the previous one but I can't have them both running at once. In other words, I can make an entry in the AB situation or I can make an entry in the KJ situation but I can't figure out how to make the code work for both.k
-
Apr 29th, 2020, 02:56 PM
#6
Re: Visual Basic Private Sub won't run
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("a:a")) Is Nothing Then
MsgBox "do something based on change in column A"
ElseIf Not Intersect(Target, Range("k:k")) Is Nothing Then
MsgBox "do something based on change in column K"
End If
End Sub
-
Apr 30th, 2020, 03:15 AM
#7
Re: Visual Basic Private Sub won't run
if you wanted to do the same thin for column A or column K
instead of the intersects, you can try lie
Code:
if target.column = 1 or target.column = 11 then target.offset(,1) = date
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
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
|