sassriverrat
Well-known Member
- Joined
- Oct 4, 2018
- Messages
- 655
I have a worksheet_Change item that is supposed to insert a timestamp (upper piece of code) and change two cells (R6 on one sheet, R9 on the rest) based on the value of another cell/sheet.
Well here's the issue- this seems to be looping so, for example, the one piece of code continually returns me to R6 (on a non-"Arrival" sheet) so I can't use any of the other cells. It's meant to change the cell as the coding below indicates and then move on to the next cell. In an ideal situation, it create this cell format when the sheet is created (via another macro) but with the ability to change (thus it's not in the creator macro) but I wasn't sure how to write that during creation piece and this looping back to R6 in this example is a problem. Ideas? Thanks for the help!
Well here's the issue- this seems to be looping so, for example, the one piece of code continually returns me to R6 (on a non-"Arrival" sheet) so I can't use any of the other cells. It's meant to change the cell as the coding below indicates and then move on to the next cell. In an ideal situation, it create this cell format when the sheet is created (via another macro) but with the ability to change (thus it's not in the creator macro) but I wasn't sure how to write that during creation piece and this looping back to R6 in this example is a problem. Ideas? Thanks for the help!
Code:
Private Sub Workbook_SheetChange(ByVal sh As Object, ByVal Target As Range)If sh.Name = "Developer" _
Or sh.Name = "Notes" _
Or sh.Name = "Ports" _
Or sh.Name = "Voyage Specifics" _
Then Exit Sub
With Application
.EnableEvents = False
.ScreenUpdating = False
'If Not Intersect(Target, Union(Range("R5"), Range("W25"))) Is Nothing Then
If Target.Address(0, 0) = "R5" Or Target.Address(0, 0) = "W25" Then
If Cells(25, 23) <> "" Then
Cells(4, 6) = Cells(25, 23).Value
Cells(4, 6).NumberFormat = "dd-mmm-yy"
ElseIf Cells(5, 18) <> "" And Cells(25, 23) = "" Then
Cells(4, 6) = Date
Cells(4, 6).NumberFormat = "dd-mmm-yy"
ElseIf Cells(5, 18) = "" And Cells(6, 23) = "" Then
Cells(4, 6) = "No Data Input"
End If
End If
If sh.Name = "Arrival" Then
If Cells(20, 26) <> "Yes" Then
Range("R6").Select
With Selection
.Locked = False
.ClearContents
.HorizontalAlignment = xlRight
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
.Borders(xlDiagonalDown).LineStyle = xlNone
.Borders(xlDiagonalUp).LineStyle = xlNone
.Borders(xlEdgeLeft).LineStyle = xlContinuous
.Borders(xlEdgeLeft).ColorIndex = 0
.Borders(xlEdgeLeft).TintAndShade = 0
.Borders(xlEdgeLeft).Weight = xlThin
.Borders(xlEdgeTop).LineStyle = xlContinuous
.Borders(xlEdgeTop).ColorIndex = 0
.Borders(xlEdgeTop).TintAndShade = 0
.Borders(xlEdgeTop).Weight = xlThin
.Borders(xlEdgeBottom).LineStyle = xlContinuous
.Borders(xlEdgeBottom).ColorIndex = 0
.Borders(xlEdgeBottom).TintAndShade = 0
.Borders(xlEdgeBottom).Weight = xlThin
.Borders(xlEdgeRight).LineStyle = xlContinuous
.Borders(xlEdgeRight).ColorIndex = 0
.Borders(xlEdgeRight).TintAndShade = 0
.Borders(xlEdgeRight).Weight = xlThin
.Borders(xlInsideVertical).LineStyle = xlNone
.Borders(xlInsideHorizontal).LineStyle = xlNone
.Interior.Pattern = xlSolid
.Interior.PatternColorIndex = xlAutomatic
.Interior.Color = 65535
.Interior.TintAndShade = 0
.Interior.PatternTintAndShade = 0
End With
ElseIf Cells(20, 26) <> "No" Then
Cells(6, 18) = "EXACT"
Range("R6").Select
With Selection
.Locked = True
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = True
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
.Font.Bold = True
.Borders(xlDiagonalDown).LineStyle = xlNone
.Borders(xlDiagonalUp).LineStyle = xlNone
.Borders(xlEdgeLeft).LineStyle = xlNone
.Borders(xlEdgeTop).LineStyle = xlContinuous
.Borders(xlEdgeTop).ColorIndex = 0
.Borders(xlEdgeTop).TintAndShade = 0
.Borders(xlEdgeTop).Weight = xlThin
.Borders(xlEdgeBottom).LineStyle = xlContinuous
.Borders(xlEdgeBottom).ColorIndex = 0
.Borders(xlEdgeBottom).TintAndShade = 0
.Borders(xlEdgeBottom).Weight = xlThin
.Borders(xlEdgeRight).LineStyle = xlNone
.Borders(xlInsideVertical).LineStyle = xlNone
.Borders(xlInsideHorizontal).LineStyle = xlNone
.Interior.Pattern = xlNone
.Interior.TintAndShade = 0
.Interior.PatternTintAndShade = 0
End With
Range("R7").Select
End If
ElseIf Cells(20, 26) <> "Yes" Then
Range("R9").Select
With Selection
.Locked = False
.ClearContents
.HorizontalAlignment = xlRight
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
.Borders(xlDiagonalDown).LineStyle = xlNone
.Borders(xlDiagonalUp).LineStyle = xlNone
.Borders(xlEdgeLeft).LineStyle = xlContinuous
.Borders(xlEdgeLeft).ColorIndex = 0
.Borders(xlEdgeLeft).TintAndShade = 0
.Borders(xlEdgeLeft).Weight = xlThin
.Borders(xlEdgeTop).LineStyle = xlContinuous
.Borders(xlEdgeTop).ColorIndex = 0
.Borders(xlEdgeTop).TintAndShade = 0
.Borders(xlEdgeTop).Weight = xlThin
.Borders(xlEdgeBottom).LineStyle = xlContinuous
.Borders(xlEdgeBottom).ColorIndex = 0
.Borders(xlEdgeBottom).TintAndShade = 0
.Borders(xlEdgeBottom).Weight = xlThin
.Borders(xlEdgeRight).LineStyle = xlContinuous
.Borders(xlEdgeRight).ColorIndex = 0
.Borders(xlEdgeRight).TintAndShade = 0
.Borders(xlEdgeRight).Weight = xlThin
.Borders(xlInsideVertical).LineStyle = xlNone
.Borders(xlInsideHorizontal).LineStyle = xlNone
.Interior.Pattern = xlSolid
.Interior.PatternColorIndex = xlAutomatic
.Interior.Color = 65535
.Interior.TintAndShade = 0
.Interior.PatternTintAndShade = 0
End With
Range("R6").Select
ElseIf Cells(20, 26) <> "No" Then
Cells(9, 18) = "EXACT"
Range("R9").Select
With Selection
.Locked = True
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = True
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
.Font.Bold = True
.Borders(xlDiagonalDown).LineStyle = xlNone
.Borders(xlDiagonalUp).LineStyle = xlNone
.Borders(xlEdgeLeft).LineStyle = xlNone
.Borders(xlEdgeTop).LineStyle = xlContinuous
.Borders(xlEdgeTop).ColorIndex = 0
.Borders(xlEdgeTop).TintAndShade = 0
.Borders(xlEdgeTop).Weight = xlThin
.Borders(xlEdgeBottom).LineStyle = xlContinuous
.Borders(xlEdgeBottom).ColorIndex = 0
.Borders(xlEdgeBottom).TintAndShade = 0
.Borders(xlEdgeBottom).Weight = xlThin
.Borders(xlEdgeRight).LineStyle = xlNone
.Borders(xlInsideVertical).LineStyle = xlNone
.Borders(xlInsideHorizontal).LineStyle = xlNone
.Interior.Pattern = xlNone
.Interior.TintAndShade = 0
.Interior.PatternTintAndShade = 0
End With
Range("R6").Select
End If
.EnableEvents = True
.ScreenUpdating = True
End With
End Sub