I have an interesting problem that I've not come across before when using Excel 2010.
I've created a spreadsheet at work that has two summary tabs which contain hyperlinks to around 30 separate sheet tabs.
On each sheet tab there is a list of unique values in column A (and other information relating to each value in columns B to D which are repeated for more than one unique value). In column E, users enter a test script name against each unique value they wish to 'reserve', and the macro picks out the unique test script names and via the COUNTIF formula counts the frequency of each test script name for each of the different values in column B.
My problem is that the macro seems to work fine if the workbook is not shared, but errors if the workbook is saved as shared. The error is 'Run time error 1004 - Unable to select the MergeCells property of the Range class'.
Here is the macro code:
Any help would be appreciated...
Thanks
Chris
I've created a spreadsheet at work that has two summary tabs which contain hyperlinks to around 30 separate sheet tabs.
On each sheet tab there is a list of unique values in column A (and other information relating to each value in columns B to D which are repeated for more than one unique value). In column E, users enter a test script name against each unique value they wish to 'reserve', and the macro picks out the unique test script names and via the COUNTIF formula counts the frequency of each test script name for each of the different values in column B.
My problem is that the macro seems to work fine if the workbook is not shared, but errors if the workbook is saved as shared. The error is 'Run time error 1004 - Unable to select the MergeCells property of the Range class'.
Here is the macro code:
Code:
Sub Get_Policies_Per_Script(updCol As Long, ShtName As String)
Dim rowctr As Long
Dim tgtrow As Long
Const ppsformula As String = "=COUNTIFS($A$3:$A$65000,I$24,$E$3:$E$65000,$G"
If updCol = 5 Then 'test name column has been modified
Workbooks("Combined Policy Matrix v0.1.xlsm").Worksheets("" & ShtName & "").Range("G25:W65000").ClearContents
Workbooks("Combined Policy Matrix v0.1.xlsm").Worksheets("" & ShtName & "").Range("G25:W65000").Select
With Selection
.Borders(xlEdgeLeft).LineStyle = xlNone
.Borders(xlEdgeTop).LineStyle = xlNone
.Borders(xlEdgeBottom).LineStyle = xlNone
.Borders(xlEdgeRight).LineStyle = xlNone
.Borders(xlInsideHorizontal).LineStyle = xlNone
.Borders(xlInsideVertical).LineStyle = xlNone
.Interior.Color = xlNone
.MergeCells = False
End With
tgtrow = 25
For rowctr = 3 To Workbooks("Combined Policy Matrix v0.1.xlsm").Worksheets("" & ShtName & "").Cells(Rows.Count, 1).End(xlUp).Row
If Workbooks("Combined Policy Matrix v0.1.xlsm").Worksheets("" & ShtName & "").Cells(rowctr, 5).Value <> "" Then
Workbooks("Combined Policy Matrix v0.1.xlsm").Worksheets("" & ShtName & "").Cells(tgtrow, 7).Value = Workbooks("Combined Policy Matrix v0.1.xlsm").Worksheets("" & ShtName & "").Cells(rowctr, 5).Value
tgtrow = tgtrow + 1
End If
Next rowctr
For rowctr = 25 To Workbooks("Combined Policy Matrix v0.1.xlsm").Worksheets("" & ShtName & "").Cells(Rows.Count, 7).End(xlUp).Row
Range("G" & rowctr & ":H" & rowctr & "").Select
Selection.MergeCells = True
Selection.RowHeight = 11.25
Next rowctr
Workbooks("Combined Policy Matrix v0.1.xlsm").Worksheets("" & ShtName & "").Range("$G$24:$H$" & Workbooks("Combined Policy Matrix v0.1.xlsm").Worksheets("" & ShtName & "").Cells(Rows.Count, 7).End(xlUp).Row & "").RemoveDuplicates Columns:=1, Header:=xlYes
With Selection
.WrapText = False
.Borders(xlEdgeLeft).LineStyle = xlNone
.Borders(xlEdgeTop).LineStyle = xlNone
.Borders(xlEdgeBottom).LineStyle = xlNone
.Borders(xlEdgeRight).LineStyle = xlNone
.Borders(xlInsideHorizontal).LineStyle = xlNone
.Borders(xlInsideVertical).LineStyle = xlNone
.Interior.Color = xlNone
End With
If Workbooks("Combined Policy Matrix v0.1.xlsm").Worksheets("" & ShtName & "").Range("G25").Value <> "" Then
Workbooks("Combined Policy Matrix v0.1.xlsm").Worksheets("" & ShtName & "").Range("G25").Select
Workbooks("Combined Policy Matrix v0.1.xlsm").Worksheets("" & ShtName & "").Range("G25:W" & Workbooks("Combined Policy Matrix v0.1.xlsm").Worksheets("" & ShtName & "").Cells(Rows.Count, 7).End(xlUp).Row & "").Select
With Selection
.Borders(xlEdgeLeft).LineStyle = xlContinuous
.Borders(xlEdgeTop).LineStyle = xlContinuous
.Borders(xlEdgeBottom).LineStyle = xlContinuous
.Borders(xlEdgeRight).LineStyle = xlContinuous
.Borders(xlInsideHorizontal).LineStyle = xlContinuous
.Borders(xlInsideVertical).LineStyle = xlContinuous
.Font.Name = "Arial"
.Font.Size = 8
.Interior.Color = RGB(255, 255, 204)
End With
Workbooks("Combined Policy Matrix v0.1.xlsm").Worksheets("" & ShtName & "").Range("I25").Select
For rowctr = 25 To Workbooks("Combined Policy Matrix v0.1.xlsm").Worksheets("" & ShtName & "").Cells(Rows.Count, 7).End(xlUp).Row
Workbooks("Combined Policy Matrix v0.1.xlsm").Worksheets("" & ShtName & "").Range("I" & rowctr & "").Formula = ppsformula & rowctr & ")"
Workbooks("Combined Policy Matrix v0.1.xlsm").Worksheets("" & ShtName & "").Range("I" & rowctr & "").Select
Selection.AutoFill Destination:=Range("I" & rowctr & ":W" & rowctr & ""), Type:=xlFillDefault
Next rowctr
End If
Workbooks("Combined Policy Matrix v0.1.xlsm").Worksheets("" & ShtName & "").Range("A2").Select
End If
End Sub
Any help would be appreciated...
Thanks
Chris