Beggininer Excel VBA TimeStamp Issue

alaskaexcel

New Member
Joined
Apr 16, 2018
Messages
2
Hi,

I am new to using VBA and have created the following by grabbing bits and pieces from the internet to make this work. Basically, I have a status column (G) with drop downs, and when I drop down and select certain values, columns are automatically updated with todays date.

However, I would like to be able to manually change the date in the automated columns producing dates, but I receive error:

"-2147417848 (80010108)
Method 'Range' of Object_Worksheet Failed"

I am able to change the date for column H (the first offset), but i cannot change the dates for any of the other columns offets 3-6, & 9. I just get the error above and it points to the row of code highlighted RED below.


Private Sub Worksheet_Change(ByVal Target As Range)

Dim WorkRng As Range
Dim Rng As Range
Dim Rng2 As Range
Dim xOffsetColumn As Integer
Set WorkRng =Intersect(Application.ActiveSheet.Range("G:G"), Target)
If Not WorkRng Is Nothing Then
Application.EnableEvents = False
For Each Rng InWorkRng
If NotVBA.IsEmpty(Rng.Value) Then
Rng.Offset(0, 1).Value = Date
Rng.Offset(0, 1).NumberFormat = "mm/dd/yyyy"
Else
Rng.Offset(0, 1).ClearContents
End If
Next
End If
Set Status = ActiveSheet.Range("G:G")
For Each Rng2 In Status
If Rng2.Value = "CV - Review" Then
Rng2.Offset(0,2).Value = Date
Rng2.Offset(0,2).NumberFormat = "mm/dd/yyyy"
Else

If Rng2.Value = "In - R0" Then
Rng2.Offset(0,3).Value = Date
Rng2.Offset(0,3).NumberFormat = "mm/dd/yyyy"
Else
If Rng2.Value = "In - R1" Then
Rng2.Offset(0,4).Value = Date
Rng2.Offset(0,4).NumberFormat = "mm/dd/yyyy"
Else
If Rng2.Value = "In - R2" Then
Rng2.Offset(0,5).Value = Date
Rng2.Offset(0,5).NumberFormat = "mm/dd/yyyy"
Else
If Rng2.Value = "In - R3" Then
Rng2.Offset(0,6).Value = Date
Rng2.Offset(0,6).NumberFormat = "mm/dd/yyyy"
Else
If Rng2.Value = "Accepted" Then
Rng2.Offset(0,9).Value = Date
Rng2.Offset(0,9).NumberFormat = "mm/dd/yyyy"


End If
End If
End If
End If
End If
End If
Next
Application.EnableEvents = True
End Sub
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
I'm not sure I can deduce exactly what you are trying to do from just your code, but give this a try.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim WorkRng   As Range
    Dim Rng       As Range
    Dim os        As Long
    
    Set WorkRng = Intersect(Application.ActiveSheet.Range("G:G"), Target)
    
    If Not WorkRng Is Nothing Then
        Application.EnableEvents = False
        For Each Rng In WorkRng
            If Not IsEmpty(Rng) Then
                Rng.Offset(0, 1).Value = Date
                Rng.Offset(0, 1).NumberFormat = "mm/dd/yyyy"
            Else
                Rng.Offset(0, 1).ClearContents
            End If
            
            Select Case Rng.Value
                Case "CV - Review": os = 2
                Case "In - R0": os = 3
                Case "In - R1": os = 4
                Case "In - R2": os = 5
                Case "In - R3": os = 6
                Case "Accepted": os = 9
                Case Else: os = 0
            End Select
            If os > 0 Then
                Rng.Offset(0, os).Value = Date
                Rng.Offset(0, os).NumberFormat = "mm/dd/yyyy"
            End If
            
        Next
    End If


    Application.EnableEvents = True
End Sub
 
Upvote 0
Thank you so much! This worked perfectly! Curious, if I wanted to return a String value based on a select case, what would I do?
 
Upvote 0
You're welcome.

A nonspecific answer to a nonspecific question...

Code:
            Dim MyString as String


            Select Case Rng.Value
                Case "CV - Review": MyString = "A"
                Case "In - R0": MyString = "B"
                Case "In - R1": MyString = "B"
                Case "In - R2": MyString = "D"
                Case "In - R3": MyString = "E"
                Case "Accepted": MyString = "Z"
                Case Else: MyString = ""
            End Select
 
Upvote 0

Forum statistics

Threads
1,215,039
Messages
6,122,802
Members
449,095
Latest member
m_smith_solihull

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