This question has been asked around the net several times but without a comprehensive program in within the macro. I have data on some sheets but I need to analyse that data more specifically on some separate 'Analysis sheets'. I believe the problem may be to do with ThisWorkbook.Sheets("sh")
function as it gives off a subscript out of range
error.
Below is the code, respond as to any changes that you would make to make this code work!
Sub Excludesheet()
Dim sh As Worksheet
Const excludeSheets As String = "1-Analysis,2-Analysis"
'Assigns a Worksheet Object to the sh variable
For Each sh In ThisWorkbook.Worksheets
If IsError(Application.Match(sh.Name, Split(excludeSheets, ","))) Then
'This is for analysis worksheets
Range("$A$1").Value = "Analysis"
Else:
'Data Sheets
Columns("A:M").AutoFit
LR = Cells(Rows.Count, "A").End(xlUp).Row
For i = LR To 2 Step -1
If Cells(i, "E").Text = "N/A" Then Rows(i).EntireRow.Delete
Next i
LastR = Cells(Rows.Count, "A").End(xlUp).Row
Dim strFormulas(1 To 3) As Variant
With ThisWorkbook.Sheets("sh")
strFormulas(1) = "=(E2-$E$2)"
strFormulas(2) = "=(G2-$G$2)"
strFormulas(3) = "=H2+I2"
Range("H2:J2").Formula = strFormulas
Range("H2:J" & LastR).FillDown
End With
End If
Next
End Sub