Hi there! I have a program that I'm trying to write that displays a date in a cell based on whether a user clicks on a specific cell.
Here are a few notes:
The date is formatted as YYYMMDD
A4 - Contains the first half of the date (ex YYYYMM)
M4 - Displays the final date in YYMMMDD format
F/G5 - Cell that the user will click to trigger change in cell M4
F/G4 - Cell that contains the number that will complete the day portion of the "date"
This is just a smaller test for just two cells, however this will be used on 18 cells...so I imagine this code will start getting really big. Rather than copying the same code over 18x, does anyone know of any ways to make this shorter, and more efficient?
Here's what I put together so far:
Any help/tips appreciated!
Here are a few notes:
The date is formatted as YYYMMDD
A4 - Contains the first half of the date (ex YYYYMM)
M4 - Displays the final date in YYMMMDD format
F/G5 - Cell that the user will click to trigger change in cell M4
F/G4 - Cell that contains the number that will complete the day portion of the "date"
This is just a smaller test for just two cells, however this will be used on 18 cells...so I imagine this code will start getting really big. Rather than copying the same code over 18x, does anyone know of any ways to make this shorter, and more efficient?
Here's what I put together so far:
Rich (BB code):
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
Application.EnableEvents = False
With Target
If .Address = Range("F5").Address Then
If IsEmpty(Range("F5").Value) = True Then
'do nothing
Else
If Range("F4").Value < 10 Then
Sheet1.Range("M4").Value = Sheet1.Range("A4").Value & "0" & Sheet1.Range("F4").Value
Else
Sheet1.Range("M4").Value = Sheet1.Range("A4").Value & Sheet1.Range("F4").Value
End If
End If
Else
If .Address = Range("G5").Address Then
If IsEmpty(Range("G5").Value) = True Then
'do nothing
Else
If Range("G4").Value < 10 Then
Sheet1.Range("M4").Value = Sheet1.Range("A4").Value & "0" & Sheet1.Range("G4").Value
Else
Sheet1.Range("M4").Value = Sheet1.Range("A4").Value & Sheet1.Range("G4").Value
End If
End If
Else
'repeat code above for other range
End If
End If
End With
Application.EnableEvents = True
End Sub
Any help/tips appreciated!