Dear All,
I have various sheets in a book with some material names / activities. I want a summary of UNIQUE material names giving their Totals (calculated from all the sheets). I have the following code but the problem is when I switch from one sheet to other and try to COMPARE the values, then I don't get the UNIQUE list. Maybe there is some problem with algorithm or something else.
Here is the code. Any help is appreciated.
<code>
For Each ws In wb.Worksheets
With ws
ws.Unprotect
If InStr(1, .Range("A1").Value, "DicoTech") > 0 Then
count = count + 1
valArea = ws.Range("B5").Value
Set locDesc = .Range("B7:B25").Find(What:="Description", LookIn:=xlValues, LookAt:= _
xlPart, SearchOrder:=xlByRows)
Set locTotal = .Range("B7:B35").Find(What:="Total", LookIn:=xlValues, LookAt:= _
xlPart, SearchOrder:=xlByRows)
startRow = locDesc.Row
endRow = locTotal.Row
Diff = (endRow - startRow) - 3
x = UBound(Mat_Name())
If count = 1 Then 'For first relevant sheet
For i = 1 To Diff
ReDim Preserve Mat_Name(i)
Mat_Name(i) = locDesc.Offset(i, 0).Value
Next i
Else 'For sheets after first relevant sheet
For i = 1 To Diff
y = i + x
ReDim Preserve Mat_Name
For check = 1 To y 'Check for UNIQUE values
If Mat_Name = Mat_Name(check) Then
Mat_Name = locDesc.Offset(i, 0).Value
End If
Next
Next i
End If
Else
End If 'Criterion for sheet selection
End With
Next
</code>
Thanks in Advance.
I have various sheets in a book with some material names / activities. I want a summary of UNIQUE material names giving their Totals (calculated from all the sheets). I have the following code but the problem is when I switch from one sheet to other and try to COMPARE the values, then I don't get the UNIQUE list. Maybe there is some problem with algorithm or something else.
Here is the code. Any help is appreciated.
<code>
For Each ws In wb.Worksheets
With ws
ws.Unprotect
If InStr(1, .Range("A1").Value, "DicoTech") > 0 Then
count = count + 1
valArea = ws.Range("B5").Value
Set locDesc = .Range("B7:B25").Find(What:="Description", LookIn:=xlValues, LookAt:= _
xlPart, SearchOrder:=xlByRows)
Set locTotal = .Range("B7:B35").Find(What:="Total", LookIn:=xlValues, LookAt:= _
xlPart, SearchOrder:=xlByRows)
startRow = locDesc.Row
endRow = locTotal.Row
Diff = (endRow - startRow) - 3
x = UBound(Mat_Name())
If count = 1 Then 'For first relevant sheet
For i = 1 To Diff
ReDim Preserve Mat_Name(i)
Mat_Name(i) = locDesc.Offset(i, 0).Value
Next i
Else 'For sheets after first relevant sheet
For i = 1 To Diff
y = i + x
ReDim Preserve Mat_Name
For check = 1 To y 'Check for UNIQUE values
If Mat_Name = Mat_Name(check) Then
Mat_Name = locDesc.Offset(i, 0).Value
End If
Next
Next i
End If
Else
End If 'Criterion for sheet selection
End With
Next
</code>
Thanks in Advance.