How would i put the Merge Code and this code together?
The point of this code is to make 2 different merged cells have multiple selections on a drop down list.
So i have a Data Validation list, and I have this code in there so that i can choose multiple items on the list and it will populate them spaced by commas.
Is there a way to have the data validation list still be able to choose multiple items, and fit your short worksheet code in there to text wrap?
Code 1 (your text wrap code)
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim ratio As Double
ratio = 0.15 ' Suits Arial 10, change number as required on different sheets.
If Target.Cells.Count > 1 Then Exit Sub
If Len(Target) / Target.Width > ratio Then SplitText (ratio)
End Sub
and Code 2, the Data validation multiple selection code.
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
ActiveSheet.Unprotect
Dim rngDV As Range
Dim oldVal As String
Dim newVal As String
If Target.Count > 2 Then GoTo exitHandler
On Error Resume Next
Set rngDV = Cells.SpecialCells(xlCellTypeAllValidation)
On Error GoTo exitHandler
If rngDV Is Nothing Then GoTo exitHandler
If Intersect(Target, rngDV) Is Nothing Then
'do nothing
Else
Application.EnableEvents = False
newVal = Target.Value
Application.Undo
oldVal = Target.Value
Target.Value = newVal
If Target.Column = 6 Then
If oldVal = "" Then
'do nothing
Else
If newVal = "" Then
'do nothing
Else
Target.Value = oldVal _
& ", " & newVal
End If
End If
End If
End If
exitHandler:
Application.EnableEvents = True
ActiveSheet.Protect
End Sub
The point of this code is to make 2 different merged cells have multiple selections on a drop down list.
So i have a Data Validation list, and I have this code in there so that i can choose multiple items on the list and it will populate them spaced by commas.
Is there a way to have the data validation list still be able to choose multiple items, and fit your short worksheet code in there to text wrap?
Code 1 (your text wrap code)
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim ratio As Double
ratio = 0.15 ' Suits Arial 10, change number as required on different sheets.
If Target.Cells.Count > 1 Then Exit Sub
If Len(Target) / Target.Width > ratio Then SplitText (ratio)
End Sub
and Code 2, the Data validation multiple selection code.
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
ActiveSheet.Unprotect
Dim rngDV As Range
Dim oldVal As String
Dim newVal As String
If Target.Count > 2 Then GoTo exitHandler
On Error Resume Next
Set rngDV = Cells.SpecialCells(xlCellTypeAllValidation)
On Error GoTo exitHandler
If rngDV Is Nothing Then GoTo exitHandler
If Intersect(Target, rngDV) Is Nothing Then
'do nothing
Else
Application.EnableEvents = False
newVal = Target.Value
Application.Undo
oldVal = Target.Value
Target.Value = newVal
If Target.Column = 6 Then
If oldVal = "" Then
'do nothing
Else
If newVal = "" Then
'do nothing
Else
Target.Value = oldVal _
& ", " & newVal
End If
End If
End If
End If
exitHandler:
Application.EnableEvents = True
ActiveSheet.Protect
End Sub