These date and time items are tough.

cblincoln43

Board Regular
Joined
Mar 12, 2002
Messages
206
I have the dates in column D, row 7 through 12. I have column H, rows 7 through 12 designated for codes.
I need to move the date for the row that i enter the code, M,S,A,E,H or W, into (column H 7 through 12) M=D18,S=D22,A=D25,E=D28,H=D31, AND W=D34.
I can't seem to make this formula work. The problem area is the;
MsgBox"in this cell you can only enter"&vbCrLf_
"M","S","A","E","H", or "W",",vbCrLf & _
"in upper case, without the quotes.",16,_
"a reminder..."
There will be numbers used in the same cells in column H., so I don't need this in the formula. Can anyone see why this formula does not move the date and how to drop the MsgBox prompt.
Thanks for putting up with these back again items. Bob

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("H7:H12")) Is Nothing Then
On Error GoTo ErrorHandler
Select Case Target.Value
Case Is = "M"
[D18].Value = Target.Offset(0, -4).Value
Case Is = "S"
[D22].Value = Target.Offset(0, -4).Value
Case Is = "A"
[D25].Value = Target.Offset(0, -4).Value
Case Is = "E"
[D28].Value = Target.Offset(0, -4).Value
Case Is = "H"
[D31].Value = Target.Offset(0, -4).Value
Case Is = "W"
[D34].Value = Target.Offset(0, -4).Value
Case Else
MsgBox "In this cell, you can only enter" & vbCrLf & _
"''M'', ''S'', ''A'', ''E'', ''H'', or ''W''," & vbCrLf & _
"in upper case, without the quotes.", 16, _
"A reminder..."
Application.EnableEvents = False
Target.Value = ""
Application.EnableEvents = True
End Select
End If
Exit Sub
ErrorHandler:
Target.Select
Exit Sub
End Sub
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
See if this works:<pre>

Private Sub Worksheet_Change(ByVal Target As Range)
Dim ValRng As Range
On Error GoTo ErrorHandler
If Not Intersect(Target, Range("H7:H12")) Is Nothing Then
Set ValRng = ActiveSheet.Cells(Target.Row, 4)
Select Case Target.Value
Case "M"
[D18].Value = ValRng: Exit Sub
Case "S"
[D22].Value = ValRng: Exit Sub
Case "A"
[D25].Value = ValRng: Exit Sub
Case "E"
[D28].Value = ValRng: Exit Sub
Case "H"
[D31].Value = ValRng: Exit Sub
Case "W"
[D34].Value = ValRng: Exit Sub
Case Else
MsgBox "In this cell, you can only enter" & vbCrLf & _
"""M"", ""S"", ""A"", ""E"", ""H"", or ""W""," & vbCrLf & _
"in upper case, without the quotes.", 16, _
"A reminder..."
Application.EnableEvents = False
Target.Value = ""
Target.Select
Application.EnableEvents = True
End Select
Set ValRng = Nothing
End If
Exit Sub
ErrorHandler:
Target.Select
End Sub</pre>

Tom
This message was edited by TsTom on 2002-05-13 08:54
 
Upvote 0

Forum statistics

Threads
1,214,424
Messages
6,119,401
Members
448,893
Latest member
AtariBaby

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