Oberon70
Board Regular
- Joined
- Jan 21, 2022
- Messages
- 160
- Office Version
- 365
- Platform
- Windows
I have the below code, which does two things.
1. it highlights the selected row, which helps keep track of manual receipting.
2. This enters the date when selecting an empty cell under the Date Column. The code will work on different reports as the column could be in a different location on other reports. (This works).
However, is it was possible to highlight only the table? And can I make this dynamic?
The other slight headache, but I will live with it unless someone knows a solution. If I fill in a cell with a colour, it is set back to no fill when I click on the spreadsheet due to the highlighting code.
1. it highlights the selected row, which helps keep track of manual receipting.
2. This enters the date when selecting an empty cell under the Date Column. The code will work on different reports as the column could be in a different location on other reports. (This works).
However, is it was possible to highlight only the table? And can I make this dynamic?
The other slight headache, but I will live with it unless someone knows a solution. If I fill in a cell with a colour, it is set back to no fill when I click on the spreadsheet due to the highlighting code.
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
Dim PortfolioCode As Variant
Dim ws As Worksheet
Dim LRow As Integer
Application.ScreenUpdating = False
Set ws = ThisWorkbook.Sheets(2)
PortfolioCode = ws.Range("B1").Value
LRow = Cells(Rows.Count, 1).End(xlUp).Row
Debug.Print ws.Name
Cells.Interior.ColorIndex = xlNone
With Cells(ActiveCell.Row, 1).Resize(1, 20).Interior
.ColorIndex = 24
.Pattern = xlSolid
End With
Select Case PortfolioCode
Case "BATINC", "BATINCT2", "BATINCRC", "BATINC", "ROBINIAE", "ROBINMV2", "ROBINRC", "ROBINT2", "ROBINXSE", "ROBINE", "ROBINUE", "ROBINAH"
If Not Application.Intersect(Target, Range("F1:F" & LRow)) Is Nothing Then
Application.EnableEvents = False
Target.Value = Date
Application.EnableEvents = True
End If
Case "ROBINIAG", "ROBINMVG2", "ROBINRCG", "ROBINXSE", "ROBING", "ROBINUG"
If Target.Column = 4 Then
Application.EnableEvents = False
Target.Value = Date
Application.EnableEvents = True
End If
If Target.Column = 6 Then
Application.EnableEvents = False
Target.Value = Date
Application.EnableEvents = True
End If
Case "ROBINIA", "ROBINMVA2", "ROBINXSA", "ROBINA", "ROBINUA"
MsgBox Anubis
Case Else
'MsgBox "Invalid code"
End Select
Application.ScreenUpdating = True
End Sub