I am trying to get the name of the sheet to copy a piece of data from one sheet to another. Sort of like using 3 tables to copy a cell into another table. It fails on the bold red code with Run-time error 1004; Application defined or object defined error.
I have tried Worksheets(WkSht.Name).Cells......, Sheets(.Name).Cells......, WkSht.Name.Cells......, Worksheets(sSheet).cells where sSheet=WkSht.name, Activesheet.cells...... and other nuances I could think of.
If there was a single worksheet then you would use: Worksheets("SheetName").Cells(x, 2) = d2(y, 2) easy peasy.
Code:
Sub HBRolestoSheets()
Dim WkBk As Workbook, WkSht As Worksheet, WkSht2 As Worksheet, WkSht3 As Worksheet
Dim Rng As Range, Rng2 As Range, Rng3 As Range, d1 As Variant, d2 As Variant, d3 As Variant, x As Long, y As Long, z As Long
strTab = "PC22V2"
Set WkBk = ThisWorkbook
Set WkSht = Worksheets(strTab)
Set WkSht2 = Worksheets("Baseline")
Set Rng = WkSht.UsedRange
Set Rng2 = WkSht2.UsedRange
d1 = Rng.Value
d2 = Rng2.Value
x = 1
y = 1
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
For Each WkSht In Worksheets
With WkSht
Select Case WkSht.Name
Case Is = "Baseline", "System Count", "", strTab
Case Else
For y = 2 To UBound(d2)
z = 1
For x = 2 To UBound(d1)
If d1(x, 2) = d2(y, 1) Then
z = d2(y, 6)
ElseIf d2(y, 6) = "" Then
z = 6
End If
ActiveSheet.Cells(z, 3) = d1(x, 14)
Next x
Next y
End Select
End With
Next WkSht
ActiveSheet.Range("C1").EntireColumn.AutoFit
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
Application.DisplayStatusBar = True
End Sub