CarolineGMartin90
New Member
- Joined
- Aug 7, 2017
- Messages
- 13
Hi there,
I have two peices of code that work, however I am struggling to get them to run together. The first bit of code that changes numbers to words (i.e. "blood", "rust" etc.) is working, however I dont want users to be able to select multiple cells - only the one they are working in. However I am not able to get that aspect of my code to work in conjuntion with the other code. I have tried adding in "application.enableEvents" however I must be doing it wrong.
Any advice greatly appreciated!
Caroline
I have two peices of code that work, however I am struggling to get them to run together. The first bit of code that changes numbers to words (i.e. "blood", "rust" etc.) is working, however I dont want users to be able to select multiple cells - only the one they are working in. However I am not able to get that aspect of my code to work in conjuntion with the other code. I have tried adding in "application.enableEvents" however I must be doing it wrong.
Any advice greatly appreciated!
Caroline
Code:
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
Worksheet_SelectionChangeA Target
Worksheet_SelectionChangeB Target
Application.EnableEvents = True
End Sub
Private Sub Worksheet_SelectionChangeA(ByVal Target As Range)
Application.EnableEvents = False
Dim rng As Range
Dim Cell As Range
Set rng = Sheets("Sheet1").Range("F:F")
For Each Cell In rng
If Cell = "" Then
Exit Sub
Else
If Cell = "N009011229028" Then
Cell = "Blood"
Else
If Cell = "N009011229035" Then
Cell = "Tissue"
Else
If Cell = "N009011229042" Then
Cell = "Bone"
Else
If Cell = "N009011229059" Then
Cell = "Rust"
Else
If Cell = "N009011229066" Then
Cell = "Sticky"
Else
If Cell = "N009011229073" Then
Cell = "Cement"
End If
End If
End If
End If
End If
End If
End If
Next
Application.EnableEvents = True
End Sub
Private Sub Worksheet_SelectionChangeB(ByVal Target As Range)
Application.EnableEvents = False
If Selection.Cells.Count > 1 Then
MsgBox "Please select only one cell."
ActiveCell.Select
End If
Application.EnableEvents = True
End Sub
Last edited by a moderator: