I figured it out. What I meant by Sheet1 was that in my Main/Master Workbook. I have Sheet1 assigned as a Summary Sheet. What that means is when I run the Macro from within Master/Main Workbook (Sheet1) the macro will go into all other workbook in the directory or through a specific workbook and will extract specific data based on the IF CONDITIONS within the macro. One of the things I needed in my summary report is to produce a table with the number of how many tabs are RED or BLUE or GREEN colored from each workbook separately. At first I had the FUNCTION statement embedded within each workbook and had assinged the first Worksheet of each workbook to produce that table. Since i have lots of Workbooks within the directory it was becoming a hassle since I need to open each workbook to view that table.
So what I was trying to do is to access those results from my Master/ Main workbook. Below how I ended up doing it and dont need the FUNCTION statement anymore
If Filename <> ThisWB Then
For i = 1 To Sheets.Count
If Sheets(i).Visible = True Then ' Exclude hidden sheets
Sheets(i).Select
Set ws = Sheets(i) ' Set Opened Worksheet as the working Worksheet
If ws.Name = "Create New NCR Form" Then GoTo NextSheet
If ws.Range("C3") = "" Then
ws.Range("O10").Copy Destination:=Main.Sheets("NCR Disposition Type Report").Cells(Destrow, 7)
ws.Range("O17").Copy Destination:=Main.Sheets("NCR Disposition Type Report").Cells(Destrow, 8)
ws.Range("L28").Copy Destination:=Main.Sheets("NCR Disposition Type Report").Cells(Destrow, 9)
' Delete comments inherited from the NCR form
Main.Sheets("NCR Disposition Type Report").Cells(Destrow, 9).Comment.Delete
' Increment destination row
Destrow = Destrow + 1
End If
If ws.Range("L28") <> "" Then ' Count tabs based on type of disposition
If ws.Range("L28") = "Reclaim" Then
k = k + 1
ElseIf ws.Range("L28") = "Repack" Then
l = l + 1
ElseIf ws.Range("L28") = "Scrap" Then
s = s + 1
ElseIf ws.Range("L28") = "Other" Then
o = o + 1
ElseIf ws.Range("L28") = "Release" Then
m = m + 1
ElseIf ws.Range("L28") = "Rework" Then
n = n + 1
End If
End If
End If
NextSheet:
Next i
Wkb.Close False
End If
End With
Main.Sheets("NCR Disposition Type Report").Range("E4").Value = k
Main.Sheets("NCR Disposition Type Report").Range("E6").Value = l
Main.Sheets("NCR Disposition Type Report").Range("E3").Value = s
Main.Sheets("NCR Disposition Type Report").Range("E8").Value = o
Main.Sheets("NCR Disposition Type Report").Range("E5").Value = m
Main.Sheets("NCR Disposition Type Report").Range("E7").Value = n
Might not be the best way to do it. But if there is better way to Optimize the code I am very much open to suggestion. I will try to use the CASE COndition but didnt figure it out yet