I am getting a conflict between a macro and a workbook sheet change. Both work correctly individually, but the combination is giving run-time error 6 Overflow
The macro:
1. Cleans sheet "Combined".
2. Loops through worksheets - copy CurrentRegion and paste as values in "Combined".
The workbook sheet change enables multiple selections from 3 columns with data validation.
When I run the macro it performs step 1 (cleans sheet "Combined"), presumably copies from the first sheet (only 20 rows in test), but then gives run-time error 6 Overflow at the start of the workbook sheet change (at If Target.Count > 1 Then Exit Sub).
Any suggestions as to a fix?
Macro
Workbook_SheetChange
The macro:
1. Cleans sheet "Combined".
2. Loops through worksheets - copy CurrentRegion and paste as values in "Combined".
The workbook sheet change enables multiple selections from 3 columns with data validation.
When I run the macro it performs step 1 (cleans sheet "Combined"), presumably copies from the first sheet (only 20 rows in test), but then gives run-time error 6 Overflow at the start of the workbook sheet change (at If Target.Count > 1 Then Exit Sub).
Any suggestions as to a fix?
Macro
Code:
Sub CombineSheets()
Dim Sh As Worksheet
On Error Resume Next
Sheets("Combined").Select
Rows("2:" & Rows.Count).ClearContents
For Each Sh In ThisWorkbook.Worksheets
If Sh.Name <> "Awards_funds_201801" And Sh.Name <> "Outcomes and Outputs" And Sh.Name <> "GSM export 20180116" _
And Sh.Name <> "Deliverables" And Sh.Name <> "Tasks" And Sh.Name <> "Lists" _
And Sh.Name <> "Combined" And Sh.Name <> "Master" Then
Sh.Activate
Range("A1").Select
Selection.CurrentRegion.Select
Selection.Offset(1, 0).Resize(Selection.Rows.Count - 1).Select
Selection.Copy
Sheets("Combined").Select
Range("A65536").End(xlUp)(2).PasteSpecial xlPasteValues
End If
Next Sh
End Sub
Workbook_SheetChange
Code:
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Dim Brng As Range
Dim Grng As Range
Dim Rrng As Range
Dim rngCols As Range
Dim FirstVal As String
Dim NextVal As String
If Target.Count > 1 Then Exit Sub
On Error Resume Next
Set Brng = Range("B:B").SpecialCells(xlCellTypeAllValidation)
Set Grng = Range("G:G").SpecialCells(xlCellTypeAllValidation)
Set Rrng = Range("R:R").SpecialCells(xlCellTypeAllValidation)
Set rngCols = Union(Brng, Grng, Rrng)
If rngCols Is Nothing Then Exit Sub
Application.EnableEvents = False
'Column B - multiple selection if condition FirstVal = Intercountry is met
If Not Intersect(Target, Brng) Is Nothing Then
NextVal = Target.Value
Application.Undo
FirstVal = Target.Value
Target.Value = NextVal
If Not NextVal = "" And Left(FirstVal, 12) = "Intercountry" Then
Target.Value = IIf(FirstVal = "", NextVal, FirstVal & ", " & NextVal)
End If
End If
'Column G - multiple selection
If Not Intersect(Target, Grng) Is Nothing Then
NextVal = Target.Value
Application.Undo
FirstVal = Target.Value
Target.Value = NextVal
If FirstVal <> "" Then
If NextVal <> "" Then
If FirstVal = NextVal Or _
InStr(1, FirstVal, ", " & NextVal) Or _
InStr(1, FirstVal, NextVal & ",") Then
Target.Value = FirstVal
Else
Target.Value = FirstVal & ", " & NextVal
End If
End If
End If
End If
'Column R - multiple selection
If Not Intersect(Target, Rrng) Is Nothing Then
NextVal = Target.Value
Application.Undo
FirstVal = Target.Value
Target.Value = NextVal
If FirstVal <> "" Then
If NextVal <> "" Then
If FirstVal = NextVal Or _
InStr(1, FirstVal, ", " & NextVal) Or _
InStr(1, FirstVal, NextVal & ",") Then
Target.Value = FirstVal
Else
Target.Value = FirstVal & ", " & NextVal
End If
End If
End If
End If
Application.EnableEvents = True
End Sub