Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Function FindQC(T As Integer, Info As Integer, DUP As Integer, LFM As Integer) As Variant
- 'Locates and returns information on QC samples: Project name, sample number, original cell address, T or D, LFM/DUP number (within)
- 'T = type of QC. 1 = LFM, 2 = DUP
- 'Info = information solicited
- ' Info = 1 QC Sample Address(s)
- ' = 2 Original Cell address(s) (DUP/LFM)
- ' = 3 QC Sample Project name (DUP/LFM)
- ' = 4 QC Sample Number (DUP/LFM)
- ' = 5 QC Sample Project name and number (DUP/LFM)
- ' = 6 QC Cell Length (including spaces)
- 'DUP =cells activated, LFM=LFM cells activated
- Dim QC As String
- Dim QC_Num As Integer 'Number of QC Cells
- Dim a(1 To 50) As Range 'Addresses of QC Cells
- Dim L(1 To 50) As Integer 'Length of QC Cells (for DUPs or LFMs)
- Dim QC_Cell(1 To 50) As String 'Content of QC Cells, w/o spaces (for DUPs or LFMs)
- Dim Project_Identifier(1 To 50) As String 'First two letters of projects for DUPs or LFMs
- Dim QC_Number(1 To 50) As String 'Sample numbers of DUPs or LFMs
- Dim TM(1 To 50) As Integer 'Total or dissolved: TM=1, D=0
- Dim Orig_a(1 To 50) As Range 'Addresses of Original Cells for DUPs/LFMs
- Dim Dilution_Factor(1 To 50) As Double 'Dilution factors of QC_Cell array
- 'Dim LFBSpikes() As Double 'Matrix containing list of all LFB spike dates, amount, and concentrations in same order as listed on Spike Values worksheet
- Dim LFBDates() As Range
- Dim LFBDatesUnion As Range
- Dim CurrentDigestSpike As Range
- Dim CurrentUndigestSpike As Range
- Dim CurrentLFBDate1 As Range
- Dim CurrentLFBDate2 As Range
- Dim CurrentLFBDate3 As Range
- Dim TopRow As Integer 'Might not be necessary, if in sub
- Dim BottomRow As Integer
- 'ReDim LFBSpikes(1 To 50, 1 To 50) As Double
- Dim q As Integer, k_1 As Integer, k_2 As Integer, k_3 As Integer, r As Integer, i_0 As Integer, a_0 As Integer, a_1 As Integer 'Counters & dummy variables
- Color_Pass = Worksheets("Spike Values").Cells(3, 1).Interior.Color
- Color_PassF = Worksheets("Spike Values").Cells(3, 1).Font.Color
- Color_Accept = Worksheets("Spike Values").Cells(4, 1).Interior.Color
- Color_AcceptF = Worksheets("Spike Values").Cells(4, 1).Font.Color
- Color_Dilute = Worksheets("Spike Values").Cells(5, 1).Interior.Color
- Color_DiluteF = Worksheets("Spike Values").Cells(5, 1).Font.Color
- Color_Fail = Worksheets("Spike Values").Cells(6, 1).Interior.Color
- Color_FailF = Worksheets("Spike Values").Cells(6, 1).Font.Color
- For a_1 = 1 To 50
- Set a(a_1) = Range("$A$1")
- Set Orig_a(a_1) = Range("$A$1")
- Next a_1
- TopRow = Top_Row(1)
- BottomRow = Top_Row(2)
- q = 1
- k_1 = 1
- k_2 = 1
- k_3 = 1
- If T = 1 Then QC = "DUP"
- If T = 2 Then QC = "LFM"
- 'If T = 3 Then QC = "LFB"
- 'If T = 4 Then QC = "LRB"
- 'T=5 ICV ' T >= 3 'Future Addons
- 'T=6 CCV 5%
- 'T=7 CCV 10%
- 'T=8 CCB
- 'T=9 SRM
- For k = TopRow To BottomRow
- If InStr(1, Cells(k, 1).Value, QC) <> 0 Then
- Set a(q) = Range(Cells(k, 1).Address)
- q = q + 1
- End If
- Next k
- 'msgbox (a(1) & "_" & a(2) & "_" & a(3) & "_")
- QC_Num = q - 1
- If T = 1 Or T = 2 Then
- For q = 1 To QC_Num
- k_1 = 1
- k_2 = 1
- k_3 = 1
- L(q) = Len(a(q).Value)
- QC_Cell(q) = Replace(a(q).Value, Space(1), Space(0))
- If Left(UCase(Trim(QC_Cell(q))), 3) = QC Then 'Determines projects for DUPs/LFMs
- Project_Identifier(q) = Mid(Trim(UCase(QC_Cell(q))), 4, 2)
- Else:
- Project_Identifier(q) = Left(Trim(UCase(QC_Cell(q))), 2)
- End If
- Do Until IsNumeric(Mid(a(q).Value, k_1, 1)) = True 'Finds sample numbers of DUPs/LFMs
- k_1 = k_1 + 1
- Loop
- k_2 = k_1
- Do Until IsNumeric(Mid(a(q).Value, k_2, 1)) = False And InStr(1, Mid(a(q).Value, k_2, 1), ".") = 0 '_
- 'And InStr(1, Mid(a(q).Value, k_2, 1), " ") = 0 And InStr(1, Mid(a(q).Value, k_2, 1), "-") = 0 And (InStr(1, Mid(a(q).Value, k_2, 1), "x") = 0 _
- 'Or InStr(1, Mid(a(q).Value, k_2, 1), "X") Or InStr(1, Mid(a(q).Value, k_2, 1), "\") Or InStr(1, Mid(a(q).Value, k_2, 1), "/") Or InStr(1, Mid(a(q).Value, k_2, 1), "-"))
- k_2 = k_2 + 1
- Loop
- QC_Number(q) = Trim(Mid(a(q).Value, k_1, k_2 - k_1))
- TM(q) = TM_Check(a(q), 0)
- Dilution_Factor(q) = Dilution(1, a(q))
- Next q
- For r = TopRow To BottomRow
- If Cells(r, 1).Value <> "" Then
- For q = 1 To QC_Num
- If InStr(1, Replace(Cells(r, 1).Value, Space(1), Space(0)), QC_Number(q)) <> 0 And InStr(1, Cells(r, 1).Value, " " & QC_Number(q)) <> 0 And Left(Trim(Cells(r, 1).Value), 2) = Project_Identifier(q) _
- And a(q).Address <> Cells(r, 1).Address And TM_Check(Range(Cells(r, 1).Address), 0) = TM(q) And InStr(1, Cells(r, 1).Value, "DUP") = 0 _
- And InStr(1, Cells(r, 1).Value, "LFM") = 0 And Dilution_Factor(q) = Dilution(1, Range(Cells(r, 1).Address)) Then
- Set Orig_a(q) = Range(Cells(r, 1).Address)
- 'msgbox (Range(Orig_a(q)).Value & "=" & QC_Cell(q))
- Else:
- If InStr(1, Replace(Cells(r, 1).Value, Space(1), Space(0)), QC_Number(q)) <> 0 And InStr(1, Cells(r, 1).Value, " " & QC_Number(q)) <> 0 And Left(Trim(Cells(r, 1).Value), 2) = Project_Identifier(q) _
- And a(q).Address <> Cells(r, 1).Address And TM_Check(Range(Cells(r, 1).Address), 0) = TM(q) And InStr(1, Cells(r, 1).Value, "DUP") = 0 _
- And InStr(1, Cells(r, 1).Value, "LFM") = 0 And QC <> "DUP" And Dilution_Factor(q) > Dilution(1, Range(Cells(r, 1).Address)) Then
- Set Orig_a(q) = Range(Cells(r, 1).Address) 'DilutionLFM > DilutionOrig, set orig
- End If
- End If
- Next q
- q = 1
- End If
- Next r
- If r = 501 Then Set Orig_a(q) = Range("$A$1")
- 'For q = 1 To 3
- ' msgbox (Orig_a(q))
- ' msgbox (QC_Cell(q))
- 'Next q
- End If
- If Info = 1 Then
- FindQC = a()
- End If
- If Info = 2 Then
- FindQC = Orig_a()
- End If
- If Info = 3 Then
- FindQC = Project_Identifier()
- End If
- If Info = 4 Then
- FindQC = QC_Number()
- End If
- If Info = 5 Then
- FindQC = QC_Cell()
- End If
- If Info = 6 Then
- FindQC = L()
- End If
- ' Info = 1 QC Sample Address(s)
- ' = 2 Original Cell address(s) (DUP/LFM)
- ' = 3 QC Sample Project name (DUP/LFM)
- ' = 4 QC Sample Number (DUP/LFM)
- ' = 5 QC Sample Project name and number (DUP/LFM)
- 'Non LFM/DUP QC: For q =1 to QC_Num /loop
- If T = 3 Then
- 'Make list of current LFB spikes available
- 'Do Until Cells(j, 1).Value = ""
- '
- ' Set LFBSpikeList(j) = Cells(j, 1).Address
- '
- ' j = j + 1
- 'Loop
- If UCase(Worksheets("Spike Values").Cells(12, 1).Value) = "LFB" Or LCase(Worksheets("Spike Values").Cells(12, 1).Value) = "laboratory fortified matrix" Then
- If (InStr(1, Worksheets("Spike Values").Cells(12, 2).Value, "LFB 1") <> 0 And InStr(1, Worksheets("Spike Values").Cells(12, 4).Value, "LFB 2") <> 0) Then
- Set CurrentLFBDate1 = Worksheets("Spike Values").Range("$C$12")
- Set CurrentLFBDate2 = Worksheets("Spike Values").Range("$E$12")
- If InStr(1, Worksheets("Spike Values").Cells(12, 6).Value, "LFB 3") <> 0 Then Set CurrentLFBDate3 = Worksheets("Spike Values").Range("$G$12")
- Else:
- If InStr(1, Worksheets("Spike Values").Cells(12, 2).Value, "LFB 2") <> 0 And InStr(1, Worksheets("Spike Values").Cells(12, 4).Value, "LFB 1") <> 0 Then
- Set CurrentLFBDate1 = Worksheets("Spike Values").Range("$E$12")
- Set CurrentLFBDate2 = Worksheets("Spike Values").Range("$C$12")
- If InStr(1, Worksheets("Spike Values").Cells(12, 6).Value, "LFB 3") <> 0 Then Set CurrentLFBDate3 = Worksheets("Spike Values").Range("$G$12")
- Else:
- msg = msgbox("Please input current LFB spike dates used in 'Spike Values' sheet", vbCritical)
- End If
- End If
- Else:
- For i = 10 To 21
- If InStr(1, Worksheets("Spike Values").Cells(i, 1).Value, "LFB") <> 0 Then
- Exit For
- End If
- Next i
- If i = 21 Then
- msg = msgbox("Please input current LFB spikes used in 'Spike Values' sheet", vbCritical)
- Else:
- If (InStr(1, Worksheets("Spike Values").Cells(i, 2).Value, "LFB 1") <> 0 And InStr(1, Worksheets("Spike Values").Cells(i, 4).Value, "LFB 2") <> 0) Then
- Set CurrentLFBDate1 = Worksheets("Spike Values").Range(Cells(i, 3).Address)
- Set CurrentLFBDate2 = Worksheets("Spike Values").Range(Cells(i, 5).Address)
- If InStr(1, Worksheets("Spike Values").Cells(i, 6).Value, "LFB 3") <> 0 Then Set CurrentLFBDate3 = Worksheets("Spike Values").Range(Cells(i, 6).Address)
- Else:
- If InStr(1, Worksheets("Spike Values").Cells(i, 2).Value, "LFB 2") <> 0 And InStr(1, Worksheets("Spike Values").Cells(i, 4).Value, "LFB 1") <> 0 Then
- Set CurrentLFBDate1 = Worksheets("Spike Values").Range(Cells(i, 5).Address)
- Set CurrentLFBDate2 = Worksheets("Spike Values").Range(Cells(i, 3).Address)
- If InStr(1, Worksheets("Spike Values").Cells(i, 6).Value, "LFB 3") <> 0 Then Set CurrentLFBDate3 = Worksheets("Spike Values").Range(Cells(i, 6).Address)
- Else:
- msg = msgbox("Please input current LFB spikes used in 'Spike Values' sheet", vbCritical)
- End If
- End If
- End If
- End If
- i_0 = 1
- 'Find LFB Spikes on list: Search I=23 on to find correct LFB spike date
- For k = 1 To QC_Num
- 'Invoke a(k); divide a(k).value by LFBspikedate_row found above
- If a(k).Value = "LFB 1" Then
- i_3 = 23
- Do
- If CurrentLFBDate1 = Worksheets("Spike Values").Cells(i_3, 3) Then 'Fix formatting: need consistent date values!''''''''''''''''''''''''
- CurrentLFBSpike1 = Worksheets("Spike Values").Cells(i_3, 4).Address
- Exit Do 'Check command!
- End If
- Loop While Worksheets("Spike Values").Cells(i_3, 1) <> ""
- End If
- If a(k).Value = "LFB 2" Then
- i_3 = 23
- Do
- If CurrentLFBDate2 = Worksheets("Spike Values").Cells(i_3, 3) Then 'Fix formatting: need consistent date values!''''''''''''''''''''''''
- CurrentLFBSpike2 = Worksheets("Spike Values").Cells(i_3, 4).Address
- Exit Do 'Check command!
- End If
- Loop While Worksheets("Spike Values").Cells(i_3, 1) <> ""
- End If
- For a_0 = 2 To 50
- 'a_1=1 Spike
- 'a_1=2 Percent Spike (Usually 0.1)
- 'a_1=3 Date of LFB spike
- 'a_1>3 Spike values
- ' If Worksheet.Cells(1, a_0).Value = "" Then Exit For
- ' For a_1 = 3 To 50
- '
- ' If Worksheet.Cells(22, a_1).Value = "" Then Exit For
- '
- ' If Replace(UCase(Left(Worksheet.Cells(1, a_0).Value, 2)), Space(1), Space(0)) = Replace(UCase(Left(Worksheet.Cells(22, a_1).Value, 2)), Space(1), Space(0)) Then
- '
- '
- '
- ' Exit For
- ' End If
- '
- '
- '
- '
- '
- '
- '
- If Worksheets("Spike Values").Cells(a_0 + 22, 1).Value = "" Then Exit For
- a_3 = 0
- If UCase(Worksheets("Spike Values").Cells(a_0 + 22, 1).Value) = "LFB" Then
- If a_3 = 1 Or a_3 = 2 Or a_3 = 3 Then
- For a_1 = 2 To 50
- If Worksheets("Spike Values").Cells(a_0 + 22, a_1).Value = "" Then Exit For
- If DateValue(CurrentLFBDate1.Value) = DateValue(Worksheets("Spike Values").Cells(a_0 + 22, 1).Value) Then
- For n_1 = 2 To 50
- For n_2 = 4 To 50
- If Replace(Left(Cells(1, n_1).Value, 2), Space(1), Space(0)) = Left(Worksheets("Spike Values").Cells(22, n_2), 2) Then
- If Worksheets("Spike Values").Cells(a_0 + 22, 1).Value <> 0 Then
- If Cells(a(k).Row, n_1).Value / Worksheets("Spike Values").Cells(a_0 + 22, 1).Value > 0.85 And Cells(a(k).Row, n_1).Value / Worksheets("Spike Values").Cells(a_0 + 22, 1).Value < 1.15 Then
- Cells(a(k).Row, n_1).Interior.Color = Color_Pass
- Cells(a(k).Row, n_1).Font.Color = Color_PassF
- Else:
- Cells(a(k).Row, n_1).Interior.Color = Color_Fail
- Cells(a(k).Row, n_1).Font.Color = Color_FailF
- End If
- Else:
- Cells(a(k).Row, n_1).Interior.Color = Color_Dilute
- Cells(a(k).Row, n_1).Font.Color = Color_DiluteF
- End If
- End If
- Next n_2
- Next n_1
- End If
- If DateValue(CurrentLFBDate2.Value) = DateValue(Worksheets("Spike Values").Cells(a_0 + 22, 1).Value) Then
- End If
- If DateValue(CurrentLFBDate3.Value) = DateValue(Worksheets("Spike Values").Cells(a_0 + 22, 1).Value) Then
- End If
- If a_1 = 3 Then
- 'LFBSpikes(a_3, a_1) = DateValue(Worksheets("Spike Values").Cells(a_0 + 22, a_1).Value)
- ''Set LFBDates(a_0) = Range(Worksheets("Spike Values").Cells(a_0 + 22, a_1).Address)
- 'Worksheets("Spike Values").Cells(i_0, 15).Value = "LFB 1" & Worksheets("Spike Values").Cells(a_0 + 22, a_1).Value
- 'Worksheets("Spike Values").Cells(i_0, 16).Value = "LFB 2" & Worksheets("Spike Values").Cells(a_0 + 22, a_1).Value
- i_0 = i_0 + 1
- Else:
- ' LFBSpikes(a_3, a_1) = Worksheets("Spike Values").Cells(a_0 + 22, a_1).Value
- End If
- Next a_1
- End If
- End If
- Next a_0
- Next k
- End If
- End Function
- Function TM_Check(C As Range, E As Integer) As Integer
- 'Checks if given cell is total or dissolved
- 'C = Cell address
- 'E = Explicit
- ' E=0 Dissolved samples implicit: e.g. "TOLL 3507" v. "TOLL 3507 TM"
- ' E=1 Dissolved samples explicitly indicated in sample title: e.g. "TOLL 3507 D" v. "TOLL 3507 T"
- 'TM_Check=0 Dissolved
- 'TM_Check=1 Total
- If (E = 0 Or IsEmpty(E) = True) And C.Value <> "" Then
- If InStr(1, UCase(C.Value), "TM") <> 0 Or (InStr(1, UCase(C.Value), "TOT") <> 0 And Left(UCase(C.Value), 3) = "TOT") Then
- TM_Check = 1
- Else:
- TM_Check = 0
- End If
- End If
- If E = 1 And C.Value <> "" Then
- k_1 = 1
- k_2 = 1
- Do Until IsNumeric(Mid(C.Value, k_1, 1)) = True 'Finds sample numbers of DUPs/LFMs
- k_1 = k_1 + 1
- Loop
- k_2 = k_1
- Do Until IsNumeric(Mid(C.Value, k_2, 1)) = False And InStr(1, Mid(C.Value, k_2, 1), ".") = 0
- k_2 = k_2 + 1
- Loop
- Do Until IsEmpty(TM_Check) = False Or k_2 = 100
- If InStr(k_2, C.Value, "D") <> 0 And InStr(k_2, C.Value, "T") = 0 Then
- TM_Check = 1
- Else:
- If InStr(k_2, C.Value, "T") <> 0 Then TM_Check = 0
- End If
- k_2 = k_2 + 1
- Loop
- End If
- If C.Value = "" Then TM_Check = 0
- End Function
- Function Dilution(T As Integer, C As Range) As Double
- 'T= Type
- ' 1=Checks if sample is dilution based on sample ID and outputs dilution factor(s)
- ' 2=Checks whether sample requires or has been diluted for whole spreadsheet based on data (T=2 defunct: see Dilutions() function for this feature)
- ' 3=
- 'C= Cell address (if T=1)
- 'C=0 If T=2
- Dim DF As Double
- Dim TopRow As Integer 'Start of data; not to be confused with Top_Row()
- Dim NumStandards As Integer 'Number of Standards
- 'Dim ElementP_2(1 To 50) As String
- Dim StandardRange As String, High_Standard As String 'Element_2 prime: 2 refers to data in lower half of spread sheet; 1 refers to information at top of spreadsheet; prime refers to the redunant inclusion of dual-wavelength elements
- Dim i As Integer, k_1 As Integer, k_2 As Integer, k_3 As Integer, E As Integer, m As Integer
- k_1 = 1
- k_2 = 1
- k_3 = 1
- 'If T = 1 Then
- Dilution = 1
- If C <> Range("$A$1").Address Then
- If InStr(1, Mid(UCase(C.Value), k_2), "X") <> 0 And (IsNumeric(InStr(1, Mid(UCase(C.Value), k_2), "X") + 1) = True Or IsNumeric(InStr(1, Mid(UCase(C.Value), k_2), "X") + 2) = True) Then
- k_1 = InStr(1, Mid(UCase(C.Value), k_2), "X")
- k_2 = 1
- k_3 = 1
- ' msgbox (Mid(UCase(Range(C).Value), k_2))
- Do Until IsNumeric(Mid(C.Value, k_1, 1)) = True 'FIX!
- ' msgbox (Mid(Range(C).Value, k_1, 1))
- k_1 = k_1 + 1
- Loop
- ' msgbox (Mid(Range(C).Value, k_1, 1))
- k_2 = k_1
- Do Until IsNumeric(Mid(C.Value, k_2, 1)) = False And InStr(Mid(C.Value, k_2, 1), ".") = 0
- ' msgbox (Mid(Range(C).Value, k_2, 1))
- k_2 = k_2 + 1
- Loop
- ' msgbox (Mid(Range(C).Value, k_2, 1))
- k_3 = k_2
- ' Do Until IsNumeric(Mid(Range(C).Value, k_2, k_3)) = False And InStr(Mid(Range(C).Value, k_2, k_3), ".") <> 0 'FIX!
- ' msgbox (Mid(Range(C).Value, k_2, k_3))
- ' k_3 = k_3 + 1
- ' Loop
- ' msgbox (Mid(Range(C).Value, k_2, k_3))
- ' msgbox (Mid(Range(C).Value, k_1, k_2 - k_1))
- Dilution = Mid(C.Value, k_1, k_2 - k_1)
- End If
- If InStr(1, Mid(UCase(C.Value), k_2), "/") <> 0 And (IsNumeric(InStr(1, Mid(UCase(C.Value), k_2), "/") + 1) = True Or IsNumeric(InStr(1, Mid(UCase(C.Value), k_2), "/") + 2) = True) Then
- k_1 = InStr(1, Mid(UCase(C.Value), k_2), "/")
- k_2 = 1
- k_3 = 1
- Do Until IsNumeric(Mid(C.Value, k_1, 1)) = True
- k_1 = k_1 + 1
- Loop
- k_2 = k_1
- Do Until IsNumeric(Mid(C.Value, k_2, 1)) = False And InStr(Mid(C.Value, k_2, 1), ".") = 0
- k_2 = k_2 + 1
- Loop
- ' k_3 = k_2
- ' Do Until IsNumeric(Mid(Range(C).Value, k_2, k_3)) = False And InStr(Mid(Range(C).Value, k_2, k_3), ".") <> 0
- ' k_3 = k_3 + 1
- ' Loop
- Dilution = Mid(C.Value, k_1, k_2 - k_1)
- End If
- If InStr(1, Mid(UCase(C.Value), k_2), "\") <> 0 And (IsNumeric(InStr(1, Mid(UCase(C.Value), k_2), "\") + 1) = True Or IsNumeric(InStr(1, Mid(UCase(C.Value), k_2), "\") + 2) = True) Then
- k_1 = InStr(1, Mid(UCase(C.Value), k_2), "\")
- k_2 = 1
- k_3 = 1
- Do Until IsNumeric(Mid(C.Value, k_1, 1)) = True
- k_1 = k_1 + 1
- Loop
- k_2 = k_1
- Do Until IsNumeric(Mid(C.Value, k_2, 1)) = False And InStr(Mid(C.Value, k_2, 1), ".") = 0
- k_2 = k_2 + 1
- Loop
- ' k_3 = k_2
- ' Do Until IsNumeric(Mid(Range(C).Value, k_2, k_3)) = False And InStr(Mid(Range(C).Value, k_2, k_3), ".") <> 0
- ' k_3 = k_3 + 1
- ' Loop
- Dilution = Mid(C.Value, k_1, k_2 - k_1)
- End If
- If (InStr(1, Mid(UCase(C.Value), k_2), "X") <> 0 And (IsNumeric(InStr(1, Mid(UCase(C.Value), k_2), "X") + 1) = True Or IsNumeric(InStr(1, Mid(UCase(C.Value), k_2), "X") + 2) = True)) And (InStr(1, Mid(UCase(C.Value), k_2), "/") <> 0 And (IsNumeric(InStr(1, Mid(UCase(C.Value), k_2), "/") + 1) = True Or IsNumeric(InStr(1, Mid(UCase(C.Value), k_2), "/") + 2) = True)) And (InStr(1, Mid(UCase(C.Value), k_2), "\") <> 0 And (IsNumeric(InStr(1, Mid(UCase(C.Value), k_2), "\") + 1) = True Or IsNumeric(InStr(1, Mid(UCase(C.Value), k_2), "\") + 2) = True)) Then
- Dilution = 1 'Doesn't make sense
- End If
- End If
- 'End if
- End Function
- Function Dilutions(T As Integer) As Variant
- Dim DF As Double
- Dim TopRow As Integer 'Start of data; not to be confused with Top_Row()
- Dim NumStandards As Integer 'Number of Standards
- 'Dim ElementP_2(1 To 50) As String
- Dim StandardRange As String, High_Standard As Double 'Element_2 prime: 2 refers to data in lower half of spread sheet; 1 refers to information at top of spreadsheet; prime refers to the redunant inclusion of dual-wavelength elements
- Dim i As Integer, k_1 As Integer, k_2 As Integer, k_3 As Integer, E As Integer, m As Integer
- Dim ISTD(1 To 2) As String
- Worksheets("Dilutions").UsedRange.ClearContents
- Dim Two_Wavelength_Elements() As String
- Dim Extraneous(1 To 5) As String
- ReDim Two_Wavelength_Elements(1 To 15) As String
- NumberDualWavelength = 0
- i_0 = 3
- i_2 = 0
- Do Until Worksheets("Spike Values").Cells(3, i_0) = ""
- i_1 = i_0 - 2
- Two_Wavelength_Elements(i_1) = Worksheets("Spike Values").Cells(3, i_0)
- NumberDualWavelength = NumberDualWavelength + 1
- i_0 = i_0 + 1
- Loop
- i_0 = 3
- For i_1 = 1 To 5
- i_0 = i_1 + 2
- Extraneous(i_1) = Worksheets("Spike Values").Cells(7, i_0)
- Next i_1
- 'Do Until Worksheets("Spike Values").Cells(7, i_0) = ""
- ' i_1 = i_0 - 2
- ' Extraneous(i_1) = Worksheets("Spike Values").Cells(7, i_0)
- ' i_0 = i_0 + 1
- ' i_2 = i_2 + 1
- 'Loop
- ReDim Preserve Two_Wavelength_Elements(1 To NumberDualWavelength) As String
- ISTD(1) = Worksheets("Spike Values").Cells(5, 3)
- ISTD(2) = Worksheets("Spike Values").Cells(5, 4)
- 'Two_Wavelength_Elements(1) = "Ca"
- 'Two_Wavelength_Elements(2) = "Mg"
- 'Two_Wavelength_Elements(3) = "Na"
- 'Two_Wavelength_Elements(4) = "P"
- 'Two_Wavelength_Elements(5) = "S"
- If T = 2 Then
- 'msgbox ("test")
- TopRow = Top_Row(1)
- BottomRow = Top_Row(2)
- 'TopRow=Top_Row(1)
- Do Until InStr(1, Cells(TopRow + 2 + i, 1).Value, "Standard") = 0
- i = i + 1
- Loop
- j = i
- Do Until InStr(1, Cells(TopRow + 2 + j, 1).Value, "Calib") = 0
- j = j + 1
- Loop
- NumStandards = i + 1
- Do Until InStr(1, Cells(j - 1, 1).Value, "Cont Calib Verif LO 5%") <> 0 And InStr(1, Cells(j, 1).Value, "Cont Calib Verif HI 5%") <> 0
- j = j + 1 'Check for off-by-one error
- Loop
- j = j + 1
- FirstSampleRow = j
- ' Sheets.Add.Name = "Dilutions"
- ' .Visible = xlSheetVeryHidden
- ' 'Copy and paste worksheets("PSL") from Top_Row down
- m = 2
- Do Until m > 100 Or Cells(TopRow, m).Value = "" '100 = arbitrary large number as upper limit of measured wavelengths
- For E = 1 To NumberDualWavelength
- If Two_Wavelength_Elements(E) = Replace(Left(Cells(TopRow, m).Value, 2), Space(1), Space(0)) Then Exit For
- Next E
- If _
- Replace(Left(Cells(TopRow, m).Value, 2), Space(1), Space(0)) <> ISTD(1) And _
- Replace(Left(Cells(TopRow, m).Value, 2), Space(1), Space(0)) <> ISTD(2) And _
- Replace(UCase(Cells(TopRow, m).Value), Space(1), Space(0)) <> Replace(UCase(Extraneous(1)), Space(1), Space(0)) And _
- Replace(UCase(Cells(TopRow, m).Value), Space(1), Space(0)) <> Replace(UCase(Extraneous(2)), Space(1), Space(0)) And _
- Replace(UCase(Cells(TopRow, m).Value), Space(1), Space(0)) <> Replace(UCase(Extraneous(3)), Space(1), Space(0)) And _
- Replace(UCase(Cells(TopRow, m).Value), Space(1), Space(0)) <> Replace(UCase(Extraneous(4)), Space(1), Space(0)) And _
- Replace(UCase(Cells(TopRow, m).Value), Space(1), Space(0)) <> Replace(UCase(Extraneous(5)), Space(1), Space(0)) Then
- If E = NumberDualWavelength + 1 Then
- 'Single-wavelength dilution check
- 'TODO: Add subroutine for QC error flags (e.g. parsing QC flag letters after values)
- StandardRange = Cells(TopRow + 1, m).Address & ":" & Cells(TopRow + NumStandards, m).Address
- High_Standard = Application.Max(Range(StandardRange))
- Do Until j = BottomRow
- DF = Dilution(1, Cells(j, 1))
- If IsNumeric(Cells(j, m).Value) = False Then
- Worksheets("Dilutions").Range(Cells(j, m).Address).Value = 2
- Else
- 'msgbox (Cells(j, m).Value / DF)
- 'msgbox (TypeName(High_Standard))
- 'msgbox ((Cells(j, m).Value / DF) < High_Standard)
- If DF <> 0 And Cells(j, m).Value / DF < High_Standard Then 'Math checked
- If DF <= 1 Then Worksheets("Dilutions").Range(Cells(j, m).Address).Value = 0
- If DF > 1 Then Worksheets("Dilutions").Range(Cells(j, m).Address).Value = 3
- Else
- Worksheets("Dilutions").Range(Cells(j, m).Address).Value = 2
- End If
- End If
- j = j + 1
- Loop
- j = FirstSampleRow
- Else:
- 'Dual wavelength dilution check
- If Replace(Left(Cells(TopRow, m).Value, 2), Space(1), Space(0)) = Replace(Left(Cells(TopRow, m + 1).Value, 2), Space(1), Space(0)) Then
- StandardRange = Cells(TopRow + 1, m).Address & ":" & Cells(TopRow + NumStandards, m + 1).Address
- StandardRange_1 = Cells(TopRow + 1, m).Address & ":" & Cells(TopRow + NumStandards, m).Address
- StandardRange_2 = Cells(TopRow + 1, m + 1).Address & ":" & Cells(TopRow + NumStandards, m + 1).Address
- If Application.Max(Range(StandardRange_1)) > Application.Max(Range(StandardRange_2)) Then 'Syntax?
- StandardRangeLO_CONC = StandardRange_2
- ColumnLO_CONC = m + 1
- If j = FirstSampleRow Then Worksheets("Dilutions").Range(Cells(TopRow - 1, m + 1).Address).Value = "LOW" ''''''
- StandardRangeHI_CONC = StandardRange_1
- ColumnHI_CONC = m
- If j = FirstSampleRow Then Worksheets("Dilutions").Range(Cells(TopRow - 1, m).Address).Value = "HIGH" ''''''
- High_StandardHI_CONC = Application.Max(Range(StandardRange_1))
- High_StandardLO_CONC = Application.Max(Range(StandardRange_2))
- Low_StandardHI_CONC = Application.Min(Range(StandardRangeHI_CONC)) 'revise Low_StandardHI_CONC definition
- If High_StandardLO_CONC + 1 >= Low_StandardHI_CONC Then
- Low_StandardHI_CONC = Application.Max(Range(StandardRangeLO_CONC)) 'revise Low_StandardHI_CONC definition
- Else:
- Low_StandardHI_CONC = Application.Min(Range(StandardRangeHIGH_CONC)) 'revise Low_StandardHI_CONC definition
- End If
- Else:
- If Application.Max(Range(StandardRange_1)) < Application.Max(Range(StandardRange_2)) Then
- StandardRangeLO_CONC = StandardRange_1
- ColumnLO_CONC = m
- If j = FirstSampleRow Then Worksheets("Dilutions").Range(Cells(TopRow - 1, m).Address).Value = "LOW" ''''''
- StandardRangeHI_CONC = StandardRange_2
- ColumnHI_CONC = m + 1
- If j = FirstSampleRow Then Worksheets("Dilutions").Range(Cells(TopRow - 1, m + 1).Address).Value = "HIGH" ''''''
- High_StandardHI_CONC = Application.Max(Range(StandardRange_2))
- High_StandardLO_CONC = Application.Max(Range(StandardRange_1))
- Low_StandardHI_CONC = Application.Min(Range(StandardRange_2)) 'revise Low_StandardHI_CONC definition
- Low_StandardHI_CONC = Application.Min(Range(StandardRangeHI_CONC))
- If High_StandardLO_CONC + 1 >= Low_StandardHI_CONC Then
- Low_StandardHI_CONC = Application.Max(Range(StandardRangeLO_CONC)) 'revise Low_StandardHI_CONC definition
- Else:
- Low_StandardHI_CONC = Application.Min(Range(StandardRangeHIGH_CONC)) 'revise Low_StandardHI_CONC definition
- End If
- End If
- End If
- Do Until j = BottomRow
- DF = Dilution(1, Cells(j, 1))
- If IsNumeric(Cells(j, ColumnLO_CONC).Value) = False And IsNumeric(Cells(j, ColumnHI_CONC).Value) = False Then
- Worksheets("Dilutions").Range(Cells(j, ColumnLO_CONC).Address).Value = 2
- Worksheets("Dilutions").Range(Cells(j, ColumnHI_CONC).Address).Value = 2
- End If
- If IsNumeric(Cells(j, ColumnLO_CONC).Value) = False And IsNumeric(Cells(j, ColumnHI_CONC).Value) = True Then
- If Cells(j, ColumnHI_CONC).Value <= High_StandardHI_CONC And Cells(j, ColumnHI_CONC).Value >= Low_StandardHI_CONC And DF <= 1 Then
- Worksheets("Dilutions").Range(Cells(j, ColumnLO_CONC).Address).Value = -1
- Worksheets("Dilutions").Range(Cells(j, ColumnHI_CONC).Address).Value = 0
- Else
- If DF > 1 And Cells(j, ColumnHI_CONC).Value / DF <= High_StandardHI_CONC And Cells(j, ColumnHI_CONC).Value / DF >= Low_StandardHI_CONC Then
- Worksheets("Dilutions").Range(Cells(j, ColumnLO_CONC).Address).Value = -1
- Worksheets("Dilutions").Range(Cells(j, ColumnHI_CONC).Address).Value = 3
- Else
- Worksheets("Dilutions").Range(Cells(j, ColumnLO_CONC).Address).Value = 2
- Worksheets("Dilutions").Range(Cells(j, ColumnHI_CONC).Address).Value = 2
- End If
- End If
- End If
- If IsNumeric(Cells(j, ColumnLO_CONC).Value) = True And IsNumeric(Cells(j, ColumnHI_CONC).Value) = False Then
- If DF <= 1 Then
- Worksheets("Dilutions").Range(Cells(j, ColumnLO_CONC).Address).Value = 0
- Worksheets("Dilutions").Range(Cells(j, ColumnHI_CONC).Address).Value = -1
- Else
- Worksheets("Dilutions").Range(Cells(j, ColumnLO_CONC).Address).Value = 3
- Worksheets("Dilutions").Range(Cells(j, ColumnHI_CONC).Address).Value = -1
- End If
- End If
- If IsNumeric(Cells(j, ColumnLO_CONC).Value) = True And IsNumeric(Cells(j, ColumnHI_CONC).Value) = True Then
- If DF <= 1 Then
- If Cells(j, ColumnLO_CONC).Value <= High_StandardLO_CONC And Cells(j, ColumnHI_CONC).Value < Low_StandardHI_CONC Then 'FIXED
- Worksheets("Dilutions").Range(Cells(j, ColumnLO_CONC).Address).Value = 0
- Worksheets("Dilutions").Range(Cells(j, ColumnHI_CONC).Address).Value = -1
- End If
- If Cells(j, ColumnLO_CONC).Value > High_StandardLO_CONC And Cells(j, ColumnHI_CONC).Value >= Low_StandardHI_CONC Then 'FIXED
- Worksheets("Dilutions").Range(Cells(j, ColumnLO_CONC).Address).Value = -1
- Worksheets("Dilutions").Range(Cells(j, ColumnHI_CONC).Address).Value = 0
- End If
- If Cells(j, ColumnLO_CONC).Value > High_StandardLO_CONC And Cells(j, ColumnHI_CONC).Value < Low_StandardHI_CONC Then 'CHECKED
- If Low_StandardHI_CONC <= High_StandardLO_CONC Then 'Check logic
- Worksheets("Dilutions").Range(Cells(j, ColumnLO_CONC).Address).Value = 5
- Worksheets("Dilutions").Range(Cells(j, ColumnHI_CONC).Address).Value = 5
- Else:
- Worksheets("Dilutions").Range(Cells(j, ColumnLO_CONC).Address).Value = 2
- Worksheets("Dilutions").Range(Cells(j, ColumnHI_CONC).Address).Value = 2
- End If
- 'Two cases: b/w standards and average values
- End If
- Else:
- If DF <> 0 Then
- If Cells(j, ColumnHI_CONC).Value / DF < High_StandardHI_CONC And Cells(j, ColumnHI_CONC).Value / DF > Low_StandardHI_CONC Then
- Worksheets("Dilutions").Range(Cells(j, ColumnLO_CONC).Address).Value = -1
- Worksheets("Dilutions").Range(Cells(j, ColumnHI_CONC).Address).Value = 3
- Else:
- If Cells(j, ColumnLO_CONC).Value / DF < High_StandardLO_CONC And Cells(j, ColumnHI_CONC).Value / DF < Low_StandardHI_CONC Then
- Worksheets("Dilutions").Range(Cells(j, ColumnLO_CONC).Address).Value = 3
- Worksheets("Dilutions").Range(Cells(j, ColumnHI_CONC).Address).Value = -1
- Else:
- If Cells(j, ColumnLO_CONC).Value / DF > High_StandardLO_CONC And Cells(j, ColumnHI_CONC).Value / DF < Low_StandardHI_CONC Then
- If Low_StandardHI_CONC <= High_StandardLO_CONC Then 'Checked logic
- Worksheets("Dilutions").Range(Cells(j, ColumnLO_CONC).Address).Value = 5
- Worksheets("Dilutions").Range(Cells(j, ColumnHI_CONC).Address).Value = 5
- Else:
- Worksheets("Dilutions").Range(Cells(j, ColumnLO_CONC).Address).Value = 2
- Worksheets("Dilutions").Range(Cells(j, ColumnHI_CONC).Address).Value = 2
- End If
- End If
- End If
- End If
- End If
- End If
- End If
- j = j + 1
- Loop
- j = FirstSampleRow
- ' Case-by-case breakdown of when to select which element for dual-wavelength element
- '
- ' **Include Val() for all numerical comparisons**
- '
- ' Case 1: Both columns maxed out: check for number listed
- ' Case 2: Low column maxed out, high column in-range (or slightly above range)
- ' Case 3: High column min'd out, low column available (possibly negative)
- ' Case 4: Both numbers available: pick appropriate range based on concentration
- ' Case 5: Low column maxed out, high column above min => either average or between standards (e.g. P)
- End If
- End If
- Else:
- 'If
- For i = 1 To 5
- If Replace(UCase(Cells(TopRow, m).Value), Space(1), Space(0)) = Replace(UCase(Extraneous(i)), Space(1), Space(0)) Then
- For j = FirstSampleRow To BottomRow - 1
- Worksheets("Dilutions").Range(Cells(j, m).Address).Value = -1
- Next j
- j = FirstSampleRow
- End If
- Next i
- End If
- m = m + 1
- Loop
- '1)Start at TopRow + number of standards/QC on Dilutions spreadsheet
- '2)Go row-by-row, check if entry = 3
- '3)If entry = 3 subroutine: Start from top_row + standard/QC and look for same project ID, sample number, and dilution factor. If Dilution(address of entry)=1, change first cell entry from 3 to 4 and second cell from 2 to 1
- '
- '
- '
- End If
- 'Output: T=2
- ' 0= No dilution needed
- ' X1= Dilution needed; performed same day
- ' 2= Dilution needed; not done
- ' 3= Diluted sample; different analytical batch
- ' X4= Diluted sample; same analytical batch
- ' 5= Averaged samples
- ' -1= Non-selected wavelength
- 'Add-on for Copypaste function: copies and pastes dilution into appropriate cell for output= 1,4
- End Function
- Sub CopyPaste_DUP()
- Dim DUPorig_address() As Range 'addresses of original cells for DUPs; limited to 50 due to FindQC function
- Dim DUP_address() As Range 'Addresses of DUPs; limited to 50 by FindQC contraint
- Dim DUP_List() As String 'List of Dups
- Dim Dilute_ListO() As String 'List of DUP original cell dilutions
- Dim Dilute_ListD() As String 'List of DUP dilutions
- Dim DUP_Project() As String 'First two letters of project for dups
- Dim DUP_Number() As String 'Project number of DUPs
- Dim TM_E() As Integer 'Indicates whether total or dissolved sample (where labelled explicitly)
- Dim TM_I() As Integer 'Indicates whether total or dissolved sample (where "dissolved" label implicit)
- Dim TopRow As Integer
- Dim BottomRow As Integer
- Dim Orig_Value As Double
- Dim DUP_Value As Double
- Dim Top_DUPs As Integer
- Dim Number_of_DUPS As Integer
- Dim Num_Standards As Integer
- Dim MDL_Row As Integer
- Dim DUP_RPD_Row As Integer
- Dim Brine As Integer 'Indicates whether or not brines/multiple dilutions are run of sample
- Dim a As Integer, a_2 As Integer, c_1 As Integer, c_2 As Integer
- 'Top_DUPs = 0
- Number_of_DUPS = 0
- Num_Standards = 6 'Add category for this value in "Spike Values" worksheet
- MDL_Row = 2
- Brine = 0
- Application.EnableEvents = False
- Color_Pass = Worksheets("Spike Values").Cells(3, 1).Interior.Color ' move to top; revise for FindQC expansion
- Color_PassF = Worksheets("Spike Values").Cells(3, 1).Font.Color
- Color_Accept = Worksheets("Spike Values").Cells(4, 1).Interior.Color
- Color_AcceptF = Worksheets("Spike Values").Cells(4, 1).Font.Color
- Color_Dilute = Worksheets("Spike Values").Cells(5, 1).Interior.Color
- Color_DiluteF = Worksheets("Spike Values").Cells(5, 1).Font.Color
- Color_Fail = Worksheets("Spike Values").Cells(6, 1).Interior.Color
- Color_FailF = Worksheets("Spike Values").Cells(6, 1).Font.Color
- ReDim DUPorig_address(1 To 50) As Range
- ReDim DUP_address(1 To 50) As Range
- ReDim DUP_List(1 To 50) As String
- ReDim DUP_Project(1 To 50) As String
- ReDim DUP_Number(1 To 50) As String
- ReDim Dilute_ListO(1 To 50) As String
- ReDim Dilute_ListD(1 To 50) As String
- ReDim TM_E(1 To 50) As Integer
- ReDim TM_I(1 To 50) As Integer
- TopRow = Top_Row(1)
- BottomRow = Top_Row(2)
- DUP_address = FindQC(1, 1, 0, 0)
- DUP_List = FindQC(1, 5, 0, 0)
- DUP_Project = FindQC(1, 3, 0, 0)
- DUP_Number = FindQC(1, 4, 0, 0)
- DUPorig_address = FindQC(1, 2, 0, 0)
- 'For a = 1 To 50 'Check logic
- ' If DUPorig_address(a).Address = Range("$A$1") Then
- ' a_1 = a
- ' For a_1 = a To 49
- ' Set DUPorig_address(a_1).Address = DUPorig_address(a_1 + 1).Address
- ' Set Dilute_ListO(a_1).Value = Dilute_ListO(a_1 + 1).Value
- ' Next a_1
- ' Set DUPorig_address(50) = Range("$A$1")
- ' Set Dilute_ListO(50) = Range("$A$1")
- ' End If
- 'Next a
- a_2 = 0
- For a = 1 To 50
- If DUP_address(a) <> Range("$A$1") And DUPorig_address(a) <> Range("$A$1") Then
- a_2 = a_2 + 1
- End If
- Next a
- For a = 1 To a_2
- Dilute_ListO(a) = Dilution(1, DUPorig_address(a))
- Dilute_ListD(a) = Dilution(1, DUP_address(a))
- TM_E(a) = TM_Check(DUP_address(a), 1)
- TM_I(a) = TM_Check(DUP_address(a), 0)
- Next a
- ReDim Preserve DUPorig_address(1 To a_2) As Range
- ReDim Preserve DUP_address(1 To a_2) As Range
- ReDim Preserve DUP_List(1 To a_2) As String
- ReDim Preserve DUP_Project(1 To a_2) As String
- ReDim Preserve DUP_Number(1 To a_2) As String
- ReDim Preserve Dilute_ListO(1 To a_2) As String
- ReDim Preserve Dilute_ListD(1 To a_2) As String
- ReDim Preserve TM_E(1 To a_2) As Integer
- ReDim Preserve TM_I(1 To a_2) As Integer
- 'For a = 1 To a_2
- ' DUPorig_address(a) = DUPorig_address1(a)
- ' DUP_address(a) = DUP_address1(a)
- ' DUP_List(a) = DUP_List1(a)
- ' DUP_Project(a) = DUP_Project1(a)
- ' DUP_Number(a) = DUP_Number1(a)
- ' DUPorig_address(a) = DUPorig_address1(a)
- ' Dilute_ListO(a) = Dilute_ListO1(a)
- ' Dilute_ListD(a) = Dilute_ListD1(a)
- ' TM_E(a) = TM_E1(a)
- ' TM_I(a) = TM_I1(a)
- 'Next a
- Dilutions (2)
- For a = 1 To a_2
- DUP_RPD_Row = 3 + a * 4
- If a > 2 Then
- 'For k = 1 To Top_Row
- ' If InStr(1, Cells(k + 1, 1).Value, "RELATIVE PERCENT DIFFERENCE") <> 0 Then
- ' Top_DUPs = Top_DUPs + 1
- ' End If
- 'Next k
- 'If Number_of_DUPS > 2 And Number_of_DUPS > Top_DUPs Then
- Insert_Dup = (Trim(Str(DUP_RPD_Row - 2)) & ":" & Trim(Str(DUP_RPD_Row + 1))) 'FIX
- Rows(Insert_Dup).Insert shift:=xlDown
- Rows(Insert_Dup).Interior.ColorIndex = xlNone
- Rows(Insert_Dup).Font.ColorIndex = xlblack
- Rows(Insert_Dup).NumberFormat = "General"
- 'For a_3 = 1 To a_2 'Not an issue with range object
- ' Set DUP_address(a_3) = DUP_address(a_3).Offset(4, 0)
- ' Set DUPorig_address(a_3) = Range(DUPorig_address(a_3)).Offset(4, 0)
- 'Next a_3
- Insert_Dup = (Trim(Str(DUP_RPD_Row - 2)) & ":" & Trim(Str(DUP_RPD_Row + 1)))
- Worksheets("Dilutions").Rows(Insert_Dup).Insert shift:=xlDown
- Worksheets("Dilutions").Rows(Insert_Dup).Interior.ColorIndex = xlNone
- Worksheets("Dilutions").Rows(Insert_Dup).Font.ColorIndex = xlblack
- Worksheets("Dilutions").Rows(Insert_Dup).NumberFormat = "General"
- Rows(DUP_RPD_Row - 4).Copy
- ActiveSheet.Paste Destination:=Worksheets("PSL").Rows(Str(DUP_RPD_Row))
- Rows(Str(DUP_RPD_Row)).Borders(xlEdgeBottom).Weight = xlMedium
- Rows(Str(DUP_RPD_Row + 2)).Borders(xlEdgeTop).Weight = xlThin
- Application.CutCopyMode = False
- TopRow = TopRow + 4
- BottomRow = BottomRow + 4
- End If
- Cells(DUP_RPD_Row, 1).Value = "RELATIVE PERCENT DIFFERENCE"
- Cells(DUP_RPD_Row, 1).Interior.Color = Color_Pass
- Cells(DUP_RPD_Row, 1).Font.Color = Color_PassF
- Cells(DUP_RPD_Row - 1, 1).Font.Bold = True
- Cells(DUP_RPD_Row - 2, 1).Font.Bold = True
- Cells(DUP_RPD_Row - 1, 1).Font.Italic = False
- Cells(DUP_RPD_Row - 2, 1).Font.Italic = False
- Rows(DUP_RPD_Row - 1).Interior.ColorIndex = xlNone
- Rows(DUP_RPD_Row - 2).Interior.ColorIndex = xlNone
- 'OrigVal = Cells(1, Range(DUPorig_address(a)).row).Value
- If DUPorig_address(a).Value <> "" Then Cells(DUP_RPD_Row - 2, 1).Value = DUPorig_address(a).Value
- If DUP_address(a).Value <> "" Then Cells(DUP_RPD_Row - 1, 1).Value = DUP_address(a).Value
- For c_1 = 2 To 70
- If Len(Cells(1, c_1).Value) > 0 Then
- Cells(DUP_RPD_Row, c_1).Value = "=ABS(" & Cells(DUP_RPD_Row, c_1).Offset(-2, 0).Address(False, False) & "-" _
- & Cells(DUP_RPD_Row, c_1).Offset(-1, 0).Address(False, False) & ")/AVERAGE(" & Cells(DUP_RPD_Row, c_1).Offset(-2, 0).Address(False, False) _
- & "," & Cells(DUP_RPD_Row, c_1).Offset(-1, 0).Address(False, False) & ")"
- If IsNumeric(Cells(DUP_RPD_Row, c_1).Value) = True Then
- If Abs(Cells(DUP_RPD_Row, c_1).Value) < 1 Then Cells(DUP_RPD_Row, c_1).NumberFormat = "0.00%"
- End If
- End If
- If Cells(1, c_1).Value <> "" Then
- Cells(DUP_RPD_Row, c_1).Interior.Color = Color_Pass
- Cells(DUP_RPD_Row, c_1).Font.Color = Color_PassF
- End If
- For c_2 = 2 To 70
- 'c_2 = 13
- 'c_1 = 15
- 'msgbox (Replace(Cells(1, c_2).Value, Space(1), Space(0)) & "'")
- 'msgbox (Replace(Left(Cells(TopRow, c_1), 2), Space(1), Space(0)) & "'")
- If Replace(Cells(1, c_2).Value, Space(1), Space(0)) = Replace(Left(Cells(TopRow, c_1), 2), Space(1), Space(0)) And Replace(Cells(1, c_2).Value, Space(1), Space(0)) <> "" Then
- 'msgbox (Worksheets("Dilutions").Cells(Range(DUPorig_address(a)).Row, c_1))
- 'If Worksheets("Dilutions").Cells(DUPorig_address(a).Row, c_1) = -1 Then
- ' Exit For
- 'End If
- If Worksheets("Dilutions").Cells(DUPorig_address(a).Row, c_1) = 0 Then
- 'DUP_Value = Cells(i, m).Value
- ''Cells(DUP_RPD_Row - 1, c_2).Value = Cells(Application.Row(DUP_address(a)), c_1).Value
- Orig_Value = Cells(DUPorig_address(a).Row, c_1).Value
- Cells(DUP_RPD_Row - 2, c_2).Value = Orig_Value
- Cells(DUP_RPD_Row, c_2).Font.ColorIndex = vbBlack
- Cells(DUP_RPD_Row, c_2).Interior.Color = Color_Pass
- Cells(DUP_RPD_Row, c_2).Font.Color = Color_PassF
- 'End If
- 'Loop
- End If
- If Worksheets("Dilutions").Cells(DUPorig_address(a).Row, c_1) = 5 Then
- If Replace(Cells(1, c_2).Value, Space(1), Space(0)) = Left(Cells(TopRow, c_1 + 1), 2) And Worksheets("Dilutions").Cells(DUPorig_address(a).Row, c_1 + 1) = 5 Then
- 'Orig_Value = Application.Average(Cells(DUPorig_address(a).Row, c_1).Value, Cells(DUPorig_address(a).Row, c_1 + 1).Value)
- Cells(DUP_RPD_Row - 2, c_2).Value = "=AVERAGE(" & Cells(DUPorig_address(a).Row, c_1).Address & ", " & Cells(DUPorig_address(a).Row, c_1 + 1).Address & ")"
- Cells(DUP_RPD_Row + 1, 1).Font.Italic = True
- Cells(DUP_RPD_Row + 1, 1).Value = "Note: averaged concentration values indicated by cell coloring"
- Range(Cells(DUP_RPD_Row + 1, 1).Address & ":" & Cells(DUP_RPD_Row + 1, 4).Address).Interior.Color = Color_Accept
- Range(Cells(DUP_RPD_Row + 1, 1).Address & ":" & Cells(DUP_RPD_Row + 1, 4).Address).Font.Color = Color_AcceptF
- Cells(DUP_RPD_Row - 2, c_2).Interior.Color = Color_Accept
- Cells(DUP_RPD_Row - 2, c_2).Font.Color = Color_AcceptF
- Else:
- If Replace(Cells(1, c_2).Value, Space(1), Space(0)) = Left(Cells(TopRow, c_1 - 1), 2) And Worksheets("Dilutions").Cells(DUPorig_address(a).Row, c_1 - 1) = 5 Then
- 'Orig_Value = Application.Average(Cells(DUPorig_address(a).Row, c_1).Value, Cells(DUPorig_address(a).Row, c_1 - 1).Value)
- Cells(DUP_RPD_Row - 2, c_2).Value = "=AVERAGE(" & Cells(DUPorig_address(a).Row, c_1).Address & ", " & Cells(DUPorig_address(a).Row, c_1 - 1).Address & ")"
- Cells(DUP_RPD_Row + 1, 1).Font.Italic = True
- Cells(DUP_RPD_Row + 1, 1).Value = "Note: averaged concentration values indicated by cell coloring"
- Range(Cells(DUP_RPD_Row + 1, 1).Address & ":" & Cells(DUP_RPD_Row + 1, 4).Address).Interior.Color = Color_Accept
- Range(Cells(DUP_RPD_Row + 1, 1).Address & ":" & Cells(DUP_RPD_Row + 1, 4).Address).Font.Color = Color_AcceptF
- Cells(DUP_RPD_Row - 2, c_2).Interior.Color = Color_Accept
- Cells(DUP_RPD_Row - 2, c_2).Font.Color = Color_AcceptF
- End If
- End If
- 'DUP_Value = Cells(i, m).Value
- 'Cells(DUP_RPD_Row - 1, c_2).Value = Cells(Application.Row(DUP_address(a)), c_1).Value
- 'Orig_Value = Cells(j, m).Value
- 'Cells(DUP_RPD_Row - 2, c_2).Value = Cells(Application.Row(DUPorig_address(a)), c_1).Value
- 'Cells(DUP_RPD_Row, c_2).Font.ColorIndex = vbBlack
- 'Cells(DUP_RPD_Row, c_2).Interior.Color = Color_Pass
- 'Cells(DUP_RPD_Row, c_2).Font.Color = Color_PassF
- 'Average two numbers, then copy/paste
- ''Shade cell accordingly
- End If
- If Worksheets("Dilutions").Cells(DUPorig_address(a).Row, c_1) = 2 Then
- Cells(DUP_RPD_Row, c_2).Value = "Dilute"
- Union(Range(Cells(DUP_RPD_Row, c_2).Address), Range(Cells(DUP_RPD_Row - 1, c_2).Address), Range(Cells(DUP_RPD_Row - 2, c_2).Address)).Interior.Color = Color_Dilute
- End If
- If Worksheets("Dilutions").Cells(DUPorig_address(a).Row, c_1) = 3 Then
- Orig_Value = Cells(DUPorig_address(a).Row, c_1).Value
- Cells(DUP_RPD_Row - 2, c_2).Value = Orig_Value
- For a_3 = 1 To a_2
- If DUP_Project(a) = DUP_Project(a_3) And DUP_Number(a) = DUP_Number(a_3) And TM_E(a) = TM_E(a_3) _
- And TM_I(a) = TM_I(a_3) And Worksheets("Dilutions").Cells(DUPorig_address(a_3).Row, c_1).Value = 2 _
- And a > a_3 And Dilute_ListO(a_3) < Dilute_ListO(a) Then
- For a_4 = 1 To a_2
- 'Checks if additional dilutions listed
- If DUP_Project(a) = DUP_Project(a_4) And DUP_Number(a) = DUP_Number(a_4) And TM_E(a) = TM_E(a_4) _
- And TM_I(a) = TM_I(a_4) And Worksheets("Dilutions").Cells(DUPorig_address(a_4).Row, c_1).Value = 2 _
- And a <> a_4 And a_3 <> a_4 And a <> a_3 And Dilute_ListO(a_3) <> Dilute_ListO(a) _
- And Dilute_ListO(a_4) <> Dilute_ListO(a) And Dilute_ListO(a_4) <> Dilute_ListO(a_3) Then
- Brine = 1
- 'msgbox ("BRINE=1 DUP_1")
- End If
- Next a_4
- If Brine <> 1 Then
- DUP_RPD_Row2 = DUP_RPD_Row - Abs(4 * (a - a_3))
- Orig_Value = Cells(DUPorig_address(a).Row, c_1).Value
- Cells(DUP_RPD_Row2 - 2, c_2).Value = Orig_Value
- Cells(DUP_RPD_Row2 - 2, c_2).Interior.Color = Color_Dilute
- End If
- End If
- Next a_3
- 'Check FindQC string for same sample ID, number, TM, but different dilution factor
- 'If found, copy/paste alternate cell to destination, highlighting value in yellow
- 'If not found, highlight percent in yellow, write "dilute," and put "--" in destination cell
- End If
- If Worksheets("Dilutions").Cells(DUP_address(a).Row, c_1) = 0 Then
- DUP_Value = Cells(DUP_address(a).Row, c_1).Value
- Cells(DUP_RPD_Row - 1, c_2).Value = DUP_Value
- End If
- If Worksheets("Dilutions").Cells(DUP_address(a).Row, c_1) = 5 Then
- If Replace(Cells(1, c_2).Value, Space(1), Space(0)) = Left(Cells(TopRow, c_1 + 1), 2) And Worksheets("Dilutions").Cells(DUP_address(a).Row, c_1 + 1) = 5 Then
- 'DUP_Value = Application.Average(Cells(DUP_address(a).Row, c_1).Value, Cells(DUP_address(a).Row, c_1 + 1).Value)
- Cells(DUP_RPD_Row - 1, c_2).Value = "=AVERAGE(" & Cells(DUP_address(a).Row, c_1).Address & ", " & Cells(DUP_address(a).Row, c_1 + 1).Address & ")"
- Cells(DUP_RPD_Row + 1, 1).Font.Italic = True
- Cells(DUP_RPD_Row + 1, 1).Value = "Note: averaged concentration values indicated by cell coloring"
- Range(Cells(DUP_RPD_Row + 1, 1).Address & ":" & Cells(DUP_RPD_Row + 1, 4).Address).Interior.Color = Color_Accept
- Range(Cells(DUP_RPD_Row + 1, 1).Address & ":" & Cells(DUP_RPD_Row + 1, 4).Address).Font.Color = Color_AcceptF
- Cells(DUP_RPD_Row - 1, c_2).Interior.Color = Color_Accept
- Cells(DUP_RPD_Row - 1, c_2).Font.Color = Color_AcceptF
- Else:
- If Replace(Cells(1, c_2).Value, Space(1), Space(0)) = Left(Cells(TopRow, c_1 - 1), 2) And Worksheets("Dilutions").Cells(DUP_address(a).Row, c_1 - 1) = 5 Then
- 'DUP_Value = Application.Average(Cells(DUP_address(a).Row, c_1).Value, Cells(DUP_address(a).Row, c_1 - 1).Value)
- Cells(DUP_RPD_Row - 1, c_2).Value = "=AVERAGE(" & Cells(DUP_address(a).Row, c_1).Address & ", " & Cells(DUP_address(a).Row, c_1 - 1).Address & ")"
- Cells(DUP_RPD_Row + 1, 1).Font.Italic = True
- Cells(DUP_RPD_Row + 1, 1).Value = "Note: averaged concentration values indicated by cell coloring"
- Range(Cells(DUP_RPD_Row + 1, 1).Address & ":" & Cells(DUP_RPD_Row + 1, 4).Address).Interior.Color = Color_Accept
- Range(Cells(DUP_RPD_Row + 1, 1).Address & ":" & Cells(DUP_RPD_Row + 1, 4).Address).Font.Color = Color_AcceptF
- Cells(DUP_RPD_Row - 1, c_2).Interior.Color = Color_Accept
- Cells(DUP_RPD_Row - 1, c_2).Font.Color = Color_AcceptF
- End If
- End If
- End If
- If Worksheets("Dilutions").Cells(DUP_address(a).Row, c_1) = 3 Then
- DUP_Value = Cells(DUP_address(a).Row, c_1).Value
- Cells(DUP_RPD_Row - 1, c_2).Value = DUP_Value
- For a_3 = 1 To a_2
- If DUP_Project(a) = DUP_Project(a_3) And DUP_Number(a) = DUP_Number(a_3) And TM_E(a) = TM_E(a_3) _
- And TM_I(a) = TM_I(a_3) And Worksheets("Dilutions").Cells(DUP_address(a_3).Row, c_1).Value = 2 _
- And a > a_3 And Dilute_ListD(a_3) < Dilute_ListD(a) Then
- For a_4 = 1 To a_2
- 'Checks if additional dilutions listed
- If DUP_Project(a) = DUP_Project(a_4) And DUP_Number(a) = DUP_Number(a_4) And TM_E(a) = TM_E(a_4) _
- And TM_I(a) = TM_I(a_4) And Worksheets("Dilutions").Cells(DUP_address(a_4).Row, c_1).Value = 2 _
- And a <> a_4 And a_3 <> a_4 And a <> a_3 And Dilute_ListD(a_3) <> Dilute_ListD(a) _
- And Dilute_ListD(a_4) <> Dilute_ListD(a) And Dilute_ListD(a_4) <> Dilute_ListD(a_3) Then
- Brine = 1
- 'msgbox ("BRINE=1 DUP_2")
- End If
- Next a_4
- If Brine <> 1 Then
- DUP_RPD_Row2 = DUP_RPD_Row - Abs(4 * (a - a_3))
- DUP_Value = Cells(DUP_address(a).Row, c_1).Value
- Cells(DUP_RPD_Row2 - 1, c_2).Value = DUP_Value
- Cells(DUP_RPD_Row2 - 1, c_2).Interior.Color = Color_Dilute
- 'Worksheets("Dilutions").Cells(DUP_address(a).Row, c_2) = 1
- If IsError(Cells(DUP_RPD_Row2, c_2)) = False Then
- If IsNumeric(Cells(DUP_RPD_Row2 - 1, c_2)) = True And IsNumeric(Cells(DUP_RPD_Row2 - 2, c_2)) = True And Cells(DUP_RPD_Row2 - 1, c_2).Value <> "" And Cells(DUP_RPD_Row2 - 2, c_2).Value <> "" Then
- If Len(Cells(1, c_1).Value) > 0 Then
- Cells(DUP_RPD_Row2, c_2).Value = "=ABS(" & Cells(DUP_RPD_Row2, c_2).Offset(-2, 0).Address(False, False) & "-" _
- & Cells(DUP_RPD_Row2, c_2).Offset(-1, 0).Address(False, False) & ")/AVERAGE(" & Cells(DUP_RPD_Row2, c_2).Offset(-2, 0).Address(False, False) _
- & "," & Cells(DUP_RPD_Row2, c_2).Offset(-1, 0).Address(False, False) & ")"
- If IsNumeric(Cells(DUP_RPD_Row2, c_2).Value) = True Then
- If Abs(Cells(DUP_RPD_Row2, c_2).Value) < 1 Then Cells(DUP_RPD_Row2, c_2).NumberFormat = "0.00%"
- End If
- Cells(DUP_RPD_Row2, c_2).Font.ColorIndex = vbBlack
- Cells(DUP_RPD_Row2, c_2).Interior.Color = Color_Pass
- Cells(DUP_RPD_Row2, c_2).Font.Color = Color_PassF
- If InStr(1, Cells(DUP_RPD_Row2, c_2).Value, "Dilute") = 0 Or IsNumeric(Cells(DUP_RPD_Row2, c_2).Offset(-1, 0).Value) = False Or IsNumeric(Cells(DUP_RPD_Row2, c_2).Offset(-2, 0).Value) = False Then
- If Cells(MDL_Row, c_2) * 10 > Cells(DUP_RPD_Row2, c_2).Offset(-1, 0).Value / 10 And Cells(MDL_Row, c_2) * 10 > Cells(DUP_RPD_Row2, c_2).Offset(-2, 0).Value / 10 Then
- 'Cells(DUP_RPD_Row2, c_2).Interior.Color = Color_Accept
- 'Cells(DUP_RPD_Row2, c_2).Font.Color = Color_AcceptF
- 'If Abs(Cells(DUP_RPD_Row2, c_2).Value) >= 1 Then Cells(DUP_RPD_Row2, c_2).NumberFormat = "0%"
- Cells(DUP_RPD_Row2, c_2).Interior.Color = Color_Dilute
- Cells(DUP_RPD_Row2, c_2).Font.Color = Color_DiluteF
- Else:
- If Abs(Cells(DUP_RPD_Row2, c_2).Value) >= 0.2 Then
- Cells(DUP_RPD_Row2, c_2).Interior.Color = Color_Fail
- Cells(DUP_RPD_Row2, c_2).Font.Color = Color_FailF
- End If
- End If
- Else:
- Cells(DUP_RPD_Row2, c_2).Interior.Color = Color_Dilute
- Cells(DUP_RPD_Row2, c_2).Font.Color = Color_DiluteF
- End If
- End If
- End If
- End If
- End If
- End If
- Next a_3
- End If
- If IsError(Cells(DUP_RPD_Row, c_2)) = False Then 'Delete all references to color below DUP_RPD_Row
- If InStr(1, Cells(DUP_RPD_Row, c_2).Value, "Dilute") = 0 Or IsNumeric(Cells(DUP_RPD_Row, c_2).Offset(-1, 0).Value) = False Or IsNumeric(Cells(DUP_RPD_Row, c_2).Offset(-2, 0).Value) = False Then
- If Cells(MDL_Row, c_2) * 10 > Cells(DUP_RPD_Row, c_2).Offset(-1, 0).Value And Cells(MDL_Row, c_2) * 10 > Cells(DUP_RPD_Row, c_2).Offset(-2, 0).Value Then
- Cells(DUP_RPD_Row, c_2).Interior.Color = Color_Accept
- Cells(DUP_RPD_Row, c_2).Font.Color = Color_AcceptF
- If Abs(Cells(DUP_RPD_Row, c_2).Value) >= 1 Then Cells(DUP_RPD_Row, c_2).NumberFormat = "0%"
- Else:
- If Abs(Cells(DUP_RPD_Row, c_2).Value) >= 0.2 Then
- Cells(DUP_RPD_Row, c_2).Interior.Color = Color_Fail
- Cells(DUP_RPD_Row, c_2).Font.Color = Color_FailF
- End If
- End If
- Else:
- Cells(DUP_RPD_Row, c_2).Interior.Color = Color_Dilute
- Cells(DUP_RPD_Row, c_2).Font.Color = Color_DiluteF
- End If
- End If
- End If
- Next c_2
- Next c_1
- Next a
- 'QC function output key:
- ' Info = 1 QC Sample Address(s)
- ' = 2 Original Cell address(s) (DUP/LFM)
- ' = 3 QC Sample Project name (DUP/LFM)
- ' = 4 QC Sample Number (DUP/LFM)
- ' = 5 QC Sample Project name and number (DUP/LFM)
- 'Dilution: if Dilutions Worksheet entry = 0, 3, or 5 search & copy/paste like address from PSL worksheet into appropriate spot
- '
- ' Case 0: Copy/paste
- ' Case 3: a. Search for neat sample within spreadsheet
- ' b. For 3's, replace analyte with 2's for same element columns
- ' c. Highlight data cell yellow, and change percentage cell color as necessary (must account for MDL determination for dilutions; important for brine samples)
- ' c.2 Do not replace in case of brines (add option to drop-down menu for brines)
- '
- ' Case 5: Average, then copy/paste
- Application.EnableEvents = True
- End Sub
- Function LFMSpike(LFMNumber As Integer) As Integer
- 'Add LFM spikes used to spreadsheet
- 'Worksheet change event for:
- '1) Change of dropdown for LFM sample type;
- '2) Change of LFM Dates setting (Cells(25+8*LFMNumber,9)
- '3) Add LFB dropdown for all "LFB 1" "LFB 2" sample types, and make changeaddress accordingly
- '4) Color sub to update colors
- Dim LFMSpikeDigest() As Range
- Dim LFMSpikeUndigest() As Range
- Dim LFMSpikePercentD() As Range
- Dim LFMSpikePercentU() As Range
- Dim LFMDigestDate(1 To 3) As Double
- Dim LFMUndigestDate(1 To 3) As Double
- Dim LFMSpikeDRow(1 To 3) As Integer 'Row location of curent spike concentrations Digested
- Dim LFMSpikeURow(1 To 3) As Integer 'Row location of curent spike concentrations Undigested/direct
- Dim LFMInformationCellD As String
- Dim LFMInformationCellU As String
- Dim LastDUPRow As Integer
- Dim j_0 As Integer
- 'Dim ChangedLFMType as integer
- 'ChangedLFMType = 0
- Color_Pass = Worksheets("Spike Values").Cells(3, 1).Interior.Color
- Color_PassF = Worksheets("Spike Values").Cells(3, 1).Font.Color
- Color_Accept = Worksheets("Spike Values").Cells(4, 1).Interior.Color
- Color_AcceptF = Worksheets("Spike Values").Cells(4, 1).Font.Color
- Color_Dilute = Worksheets("Spike Values").Cells(5, 1).Interior.Color
- Color_DiluteF = Worksheets("Spike Values").Cells(5, 1).Font.Color
- Color_Fail = Worksheets("Spike Values").Cells(6, 1).Interior.Color
- Color_FailF = Worksheets("Spike Values").Cells(6, 1).Font.Color
- 'Dim SRMSpike()
- 'Dim "
- 'Dim "
- 'Dim "
- ReDim LFMSpikeDigest(1 To 50, 1 To 3) As Range
- ReDim LFMSpikeUndigest(1 To 50, 1 To 3) As Range
- ReDim LFMSpikePercentD(1 To 3) As Range
- ReDim LFMSpikePercentU(1 To 3) As Range
- For a_0 = 1 To 50
- For a_1 = 1 To 3
- Set LFMSpikeDigest(a_0, a_1) = Worksheets("Spike Values").Range("$A$1")
- Set LFMSpikeUndigest(a_0, a_1) = Worksheets("Spike Values").Range("$A$1")
- Next a_1
- Next a_0
- 'Redim LFMSpikeDigest(1 To 50) As Double 'Check length of Spike values columns, and redimension accordingly
- 'ReDim LFMSpikeUndigest(1 To 50) As Double ' " " "
- Dim CurrentDigestSpike As Range 'Address of cell listing which spike is current spike (Digested LFM Spike)
- Dim CurrentUndigestSpike As Range 'Address of cell listing which spike is current spike (Undigested/direct analysis LFM Spike)
- Dim LFMLetter As String * 1
- Dim InputError As Integer, i_0 As Integer, msg As Integer
- Dim PercentRecoveryRow As Integer
- For j_0 = 1 To 100
- If InStr(1, Cells(j_0, 1).Value, "RELATIVE PERCENT DIFFERENCE") <> 0 Then LastDUPRow = j_0
- Next j_0
- For i_0 = 1 To 3
- LFMDigestDate(i_0) = 0
- LFMUndigestDate(i_0) = 0
- Next i_0
- PercentRecoveryRow = LastDUPRow + LFMNumber * 8
- If (InStr(1, Worksheets("Spike Values").Cells(10, 1).Value, "Digest") <> 0 And InStr(1, Worksheets("Spike Values").Cells(11, 1).Value, "Direct") <> 0) _
- Or (InStr(1, Worksheets("Spike Values").Cells(10, 1).Value, "Digest") <> 0 And InStr(1, Worksheets("Spike Values").Cells(11, 1).Value, "Undig") <> 0) Then
- Set CurrentDigestSpike = Worksheets("Spike Values").Range("$A$10:G$10")
- Set CurrentUndigestSpike = Worksheets("Spike Values").Range("$A$11:$G$11")
- Else:
- If (InStr(1, Worksheets("Spike Values").Cells(10, 1).Value, "Direct") <> 0 And InStr(1, Worksheets("Spike Values").Cells(11, 1).Value, "Digest") <> 0) _
- Or (InStr(1, Worksheets("Spike Values").Cells(10, 1).Value, "Undig") <> 0 And InStr(1, Worksheets("Spike Values").Cells(11, 1).Value, "Digest") <> 0) Then
- Set CurrentUndigestSpike = Worksheets("Spike Values").Range("$A$10:$G$10")
- Set CurrentDigestSpike = Worksheets("Spike Values").Range("$A$11:$G$11")
- Else:
- InputError = 0
- For i_0 = 12 To 21
- If InStr(1, Worksheets("Spike Values").Cells(i_0, 1), "Direct") <> 0 Then
- Set CurrentUndigestSpike = Worksheets("Spike Values").Range(Cells(i_0, 1).Address & ":" & Cells(i_0, 7).Address)
- InputError = 1 + InputError
- End If
- If InStr(1, Worksheets("Spike Values").Cells(i_0, 1), "Digest") <> 0 Or InStr(1, Worksheets("Spike Values").Cells(i_0, 1), "Undig") <> 0 Then
- Set CurrentDigestSpike = Worksheets("Spike Values").Range(Cells(i_0, 1).Address & ":" & Cells(i_0, 7).Address)
- InputError = 1 + InputError
- End If
- Next i_0
- If InputError < 2 Then
- msg = msgbox("Please input current LFM spikes used in 'Spike Values' sheet", vbCritical)
- Exit Function
- End If
- End If
- End If
- For i_0 = 1 To 3
- i_1 = 2 * i_0 + 1
- 'Worksheets("Spike Values").Cells(CurrentDigestSpike.Row, i_1).NumberFormat = "General"
- If Worksheets("Spike Values").Cells(CurrentDigestSpike.Row, i_1).Value <> 0 Then
- LFMDigestDate(i_0) = DateValue(Worksheets("Spike Values").Cells(CurrentDigestSpike.Row, i_1).Value)
- Else:
- LFMDigestDate(i_0) = 0
- End If
- 'Worksheets("Spike Values").Cells(CurrentDigestSpike.Row, i_1).NumberFormat = "mm/dd/yy;@"
- 'Worksheets("Spike Values").Cells(CurrentUndigestSpike.Row, i_1).NumberFormat = "General"
- If Worksheets("Spike Values").Cells(CurrentUndigestSpike.Row, i_1).Value <> 0 Then
- LFMUndigestDate(i_0) = DateValue(Worksheets("Spike Values").Cells(CurrentUndigestSpike.Row, i_1).Value)
- Else:
- LFMUndigestDate(i_0) = 0
- End If
- 'Worksheets("Spike Values").Cells(CurrentUndigestSpike.Row, i_1).NumberFormat = "mm/dd/yy;@"
- Next i_0
- For i_0 = 1 To 3
- i_2 = 23 'Start of LFM et al spike concentrations
- i_1 = i_0 * 2 + 1
- If i_0 = 1 Then LFMLetter = "A"
- If i_0 = 2 Then LFMLetter = "B"
- If i_0 = 3 Then LFMLetter = "C"
- Do Until Worksheets("Spike Values").Cells(i_2, 1).Value = ""
- 'Worksheets("Spike Values").Cells(i_2, 3).NumberFormat = "General"
- If InStr(1, Worksheets("Spike Values").Cells(i_2, 1).Value, LFMLetter) <> 0 Then
- If Worksheets("Spike Values").Cells(i_2, 3).Value <> "" Then
- If DateValue(Worksheets("Spike Values").Cells(i_2, 3).Value) = LFMDigestDate(i_0) Then
- LFMSpikeDRow(i_0) = i_2
- Set LFMSpikePercentD(i_0) = Range(Worksheets("Spike Values").Cells(i_2, 2).Address)
- End If
- End If
- End If
- If InStr(1, Worksheets("Spike Values").Cells(i_2, 1).Value, LFMLetter) <> 0 Then
- If Worksheets("Spike Values").Cells(i_2, 3).Value <> "" Then
- If DateValue(Worksheets("Spike Values").Cells(i_2, 3).Value) = LFMUndigestDate(i_0) Then
- LFMSpikeURow(i_0) = i_2
- Set LFMSpikePercentU(i_0) = Range(Worksheets("Spike Values").Cells(i_2, 2).Address)
- End If
- End If
- End If
- 'Worksheets("Spike Values").Cells(i_2, 3).NumberFormat = "mm/dd/yy;@"
- i_2 = i_2 + 1
- Loop
- Next i_0
- For a_0 = 1 To 50
- a_1 = a_0 + 3 '3=Start column of element spike listing
- Set LFMSpikeDigest(a_0, 1) = Range(Worksheets("Spike Values").Cells(LFMSpikeDRow(1), a_1).Address)
- If LFMSpikeDRow(2) <> 0 Then
- Set LFMSpikeDigest(a_0, 2) = Range(Worksheets("Spike Values").Cells(LFMSpikeDRow(2), a_1).Address)
- Else:
- Set LFMSpikeDigest(a_0, 2) = Range("$A$1")
- End If
- If LFMSpikeDRow(3) = 0 Then
- Set LFMSpikeDigest(a_0, 3) = Range("$A$1")
- Else:
- Set LFMSpikeDigest(a_0, 3) = Range(Worksheets("Spike Values").Cells(LFMSpikeDRow(3), a_1).Address)
- End If
- Set LFMSpikeUndigest(a_0, 1) = Range(Worksheets("Spike Values").Cells(LFMSpikeURow(1), a_1).Address)
- If LFMSpikeURow(2) <> 0 Then
- Set LFMSpikeUndigest(a_0, 2) = Range(Worksheets("Spike Values").Cells(LFMSpikeURow(2), a_1).Address)
- Else:
- Set LFMSpikeUndigest(a_0, 2) = Range("$A$1")
- End If
- If LFMSpikeURow(3) = 0 Then
- Set LFMSpikeUndigest(a_0, 3) = Range("$A$1")
- Else:
- Set LFMSpikeUndigest(a_0, 3) = Range(Worksheets("Spike Values").Cells(LFMSpikeURow(3), a_1).Address)
- End If
- Next a_0
- If Cells(PercentRecoveryRow - 6, 1).Value = "" Then
- 'Insert Brine, Soil cases
- If InStr(1, UCase(Cells(PercentRecoveryRow - 5, 1).Value), "TO") <> 0 Or InStr(1, UCase(Cells(PercentRecoveryRow - 5, 1).Value), "PS") <> 0 Or InStr(1, UCase(Cells(PercentRecoveryRow - 5, 1).Value), "CA") <> 0 Or InStr(1, UCase(Cells(PercentRecoveryRow - 5, 1).Value), "VI") <> 0 Or InStr(1, UCase(Cells(PercentRecoveryRow - 5, 1).Value), "IL") <> 0 Or InStr(1, UCase(Cells(PercentRecoveryRow - 5, 1).Value), "NP") <> 0 Then
- ChangedLFMType = 1
- Cells(PercentRecoveryRow - 6, 1).Value = "DIGESTED SAMPLES (e.g. TOLLWAY)"
- Cells(PercentRecoveryRow - 6, 1).Interior.Color = Color_Dilute
- Else:
- If InStr(1, UCase(Cells(PercentRecoveryRow - 5, 1).Value), "MG") <> 0 Then
- Cells(PercentRecoveryRow - 6, 1).Value = "DIRECT ANALYSIS HIGH VOLUME (e.g. PS Cu)"
- Cells(PercentRecoveryRow - 6, 1).Interior.Color = Color_Dilute
- Cells(PercentRecoveryRow - 6, 2).Interior.Color = Color_Dilute
- Else:
- If InStr(1, UCase(Cells(PercentRecoveryRow - 5, 1).Value), "OO") <> 0 Then
- Cells(PercentRecoveryRow - 6, 1).Value = "DIRECT ANALYSIS LOW VOLUME"
- Cells(PercentRecoveryRow - 6, 1).Interior.Color = Color_Dilute
- End If
- End If
- End If
- End If
- 'Match LFM Spike first
- If InStr(1, Cells(PercentRecoveryRow - 6, 1).Value, "DIGESTED") <> 0 Then
- For a_0 = 2 To 50 'PSL Worksheet Top row element listing
- If Cells(1, a_0).Value = "" Then
- Exit For
- End If
- For a_1 = 1 To 50 'Spike Values Worksheet element listing
- If InStr(Worksheets("Spike Values").Cells(22, LFMSpikeDigest(a_1, 1).Column).Value, Replace(Cells(1, a_0).Value, Space(1), Space(0))) <> 0 Then
- If LFMSpikeDigest(a_1, 2).Address <> Range("$A$1").Address Then
- If LFMSpikeDigest(a_1, 3).Address <> Range("$A$1").Address Then
- Cells(PercentRecoveryRow - 1, a_0).Value = "='Spike Values'!" & LFMSpikeDigest(a_1, 1).Address & "+'Spike Values'!" & LFMSpikeDigest(a_1, 2).Address & "+'Spike Values'!" & LFMSpikeDigest(a_1, 3).Address
- Exit For
- Else:
- Cells(PercentRecoveryRow - 1, a_0).Value = "='Spike Values'!" & LFMSpikeDigest(a_1, 1).Address & "+'Spike Values'!" & LFMSpikeDigest(a_1, 2).Address
- Exit For
- End If
- Else:
- Cells(PercentRecoveryRow - 1, a_0).Value = "='Spike Values'!" & LFMSpikeDigest(a_1, 1).Address
- Exit For
- End If
- End If
- Next a_1
- Next a_0
- Cells(PercentRecoveryRow - 6, 8).HorizontalAlignment = xlRight
- Cells(PercentRecoveryRow - 6, 8).Value = "LFM Spikes ="
- For i_0 = 1 To 3
- If i_0 = 1 Then LFMLetter = "A"
- If i_0 = 2 Then LFMLetter = "B"
- If i_0 = 3 Then LFMLetter = "C"
- If LFMDigestDate(i_0) <> 0 Then
- 'LFMDigestDate(i_0).NumberFormat = "mm/dd/yy;@"
- LFMInformationCellD = LFMInformationCellD & "Spike " & LFMLetter & ": " & Worksheets("Spike Values").Cells(LFMSpikeDRow(i_0), 3).Value & ", "
- End If
- Next i_0
- LFMInformationCellD = Left(LFMInformationCellD, Len(LFMInformationCellD) - 2)
- Cells(PercentRecoveryRow - 6, 9).Value = LFMInformationCellD
- Else:
- If InStr(1, Cells(PercentRecoveryRow - 6, 1).Value, "DIRECT") <> 0 Or InStr(1, Cells(PercentRecoveryRow - 6, 1).Value, "BRINE") <> 0 Then
- For a_0 = 2 To 50
- If Cells(1, a_0).Value = "" Then
- Exit For
- End If
- For a_1 = 1 To 50
- If InStr(Worksheets("Spike Values").Cells(22, LFMSpikeUndigest(a_1, 1).Column).Value, Replace(Cells(1, a_0).Value, Space(1), Space(0))) <> 0 Then
- If LFMSpikeUndigest(a_1, 2).Address <> Range("$A$1").Address Then
- If LFMSpikeUndigest(a_1, 3).Address <> Range("$A$1").Address Then
- Cells(PercentRecoveryRow - 1, a_0).Value = "='Spike Values'!" & LFMSpikeUndigest(a_1, 1).Address & "+'Spike Values'!" & LFMSpikeUndigest(a_1, 2).Address & "+'Spike Values'!" & LFMSpikeUndigest(a_1, 3).Address
- Exit For
- Else:
- Cells(PercentRecoveryRow - 1, a_0).Value = "='Spike Values'!" & LFMSpikeUndigest(a_1, 1).Address & "+'Spike Values'!" & LFMSpikeUndigest(a_1, 2).Address
- Exit For
- End If
- Else:
- Cells(PercentRecoveryRow - 1, a_0).Value = "='Spike Values'!" & LFMSpikeUndigest(a_1, 1).Address
- Exit For
- End If
- End If
- Next a_1
- Next a_0
- Cells(PercentRecoveryRow - 6, 8).HorizontalAlignment = xlRight
- Cells(PercentRecoveryRow - 6, 8).Value = "LFM Spikes ="
- For i_0 = 1 To 3
- If i_0 = 1 Then LFMLetter = "A"
- If i_0 = 2 Then LFMLetter = "B"
- If i_0 = 3 Then LFMLetter = "C"
- If LFMDigestDate(i_0) <> 0 Then
- 'LFMDigestDate(i_0).NumberFormat = "mm/dd/yy;@"
- LFMInformationCellU = LFMInformationCellU & "Spike " & LFMLetter & ": " & Worksheets("Spike Values").Cells(LFMSpikeURow(i_0), 3).Value & ", "
- End If
- Next i_0
- LFMInformationCellU = Left(LFMInformationCellU, Len(LFMInformationCellU) - 2)
- Cells(PercentRecoveryRow - 6, 9).Value = LFMInformationCellU
- Else:
- If InStr(1, Cells(PercentRecoveryRow - 6, 1).Value, "SOIL") <> 0 Then
- ' SRM-value paste into PSL spreadsheet here (possibly including weights in extraneous PSL LFM row for calculation step)
- '
- 'For soils feature, to be added
- 'Include SRM date modification where LFM date paste normally goes
- '
- '
- End If
- End If
- End If
- For a_0 = 2 To 50
- If Cells(1, a_0).Value = "" Then
- Exit For
- End If
- Cells(PercentRecoveryRow, a_0).Value = "=" & Cells(PercentRecoveryRow - 2, a_0).Address(False, False) & "/" & Cells(PercentRecoveryRow - 1, a_0).Address(False, False)
- Cells(PercentRecoveryRow, a_0).NumberFormat = "0%"
- Next a_0
- If InStr(1, Cells(PercentRecoveryRow - 6, 1).Value, "DIGESTED") <> 0 Then 'Case-by-case breakdown of formulas to paste for LFM PercentRecovery row
- For a_0 = 2 To 50
- If Cells(1, a_0).Value = "" Then
- Exit For
- End If
- Cells(PercentRecoveryRow - 2, a_0).Value = "=(" & Cells(PercentRecoveryRow - 4, a_0).Address(False, False) & "-" & Cells(PercentRecoveryRow - 5, a_0).Address(False, False) & ")"
- Next a_0
- End If
- If InStr(1, Cells(PercentRecoveryRow - 6, 1).Value, "DIRECT ANALYSIS HIGH VOLUME") <> 0 Or InStr(Cells(PercentRecoveryRow - 6, 1).Value, "DIRECT ANALYSIS LOW VOLUME") <> 0 Or InStr(Cells(PercentRecoveryRow - 6, 1).Value, "BRINE") <> 0 Then
- For a_0 = 2 To 50
- If Cells(1, a_0).Value = "" Then
- Exit For
- End If
- If LFMSpikeUndigest(1, 3) <> Range("$A$1") Then
- Cells(PercentRecoveryRow - 2, a_0).Value = "=" & Cells(PercentRecoveryRow - 4, a_0).Address(False, False) & "-(" & Cells(PercentRecoveryRow - 5, a_0).Address(False, False) & "*(1-('Spike Values'!" & LFMSpikePercentU(1).Address & "+ 'Spike Values'!" & LFMSpikePercentU(2).Address & "+'Spike Values'!" & LFMSpikePercentU(3).Address & ")))"
- Else:
- If LFMSpikeUndigest(1, 2) <> Range("$A$1") Then
- Cells(PercentRecoveryRow - 2, a_0).Value = "=" & Cells(PercentRecoveryRow - 4, a_0).Address(False, False) & "-(" & Cells(PercentRecoveryRow - 5, a_0).Address(False, False) & "*(1-('Spike Values'!" & LFMSpikePercentU(1).Address & "+ 'Spike Values'!" & LFMSpikePercentU(2).Address & ")))"
- Else:
- Cells(PercentRecoveryRow - 2, a_0).Value = "=" & Cells(PercentRecoveryRow - 4, a_0).Address(False, False) & "-(" & Cells(PercentRecoveryRow - 5, a_0).Address(False, False) & "*(1-'Spike Values'!" & LFMSpikePercentU(1).Address & "))"
- End If
- End If
- If InStr(Cells(PercentRecoveryRow - 6, 1).Value, "BRINE") <> 0 Then
- DF = Dilution(1, Range(Cells(PercentRecoveryRow - 5, 1).Address))
- Cells(PercentRecoveryRow - 2, a_0).Value = Cells(PercentRecoveryRow - 2, a_0).Value & "/" & DF
- Cells(PercentRecoveryRow, a_0).NumberFormat = "0%"
- End If
- Next a_0
- End If
- If InStr(Cells(PercentRecoveryRow - 6, 1).Value, "SOIL") <> 0 Then
- '
- '
- 'For Soils feature upgrade'
- '
- End If
- LFMSpike = ChangedLFMType
- End Function
- Sub CopyPaste_LFM()
- Dim LFMorig_address() As Range 'addresses of original cells for DUPs; limited to 50 due to FindQC function
- Dim LFM_address() As Range 'Addresses of DUPs; limited to 50 by FindQC contraint
- Dim LFM_List() As String 'List of Dups
- Dim Dilute_ListO() As String 'List of DUP original cell dilutions
- Dim Dilute_ListD() As String 'List of DUP dilutions
- Dim LFM_Project() As String 'First two letters of project for dups
- Dim LFM_Number() As String 'Project number of DUPs
- Dim TM_E() As Integer 'Indicates whether total or dissolved sample (where labelled explicitly)
- Dim TM_I() As Integer 'Indicates whether total or dissolved sample (where "dissolved" label implicit)
- Dim TopRow As Integer
- Dim BottomRow As Integer
- Dim LastDUPRow As Integer
- Dim Orig_Value As Double
- Dim LFM_Value As Double
- Dim Top_LFMs As Integer
- Dim Number_of_LFMs As Integer
- Dim Num_Standards As Integer
- Dim MDL_Row As Integer
- Dim PercentRecoveryRow As Integer
- Dim ChangedLFMType As Integer
- Dim Brine As Integer 'Indicates whether or not brines/multiple dilutions are run of sample
- Dim a As Integer, j_0 As Integer, a_2 As Integer, c_1 As Integer, c_2 As Integer
- Number_of_LFMs = 0
- Num_Standards = 6 'Add category for this value in "Spike Values" worksheet
- MDL_Row = 2
- Brine = 0
- Application.EnableEvents = False
- Color_Pass = Worksheets("Spike Values").Cells(3, 1).Interior.Color
- Color_PassF = Worksheets("Spike Values").Cells(3, 1).Font.Color
- Color_Accept = Worksheets("Spike Values").Cells(4, 1).Interior.Color
- Color_AcceptF = Worksheets("Spike Values").Cells(4, 1).Font.Color
- Color_Dilute = Worksheets("Spike Values").Cells(5, 1).Interior.Color
- Color_DiluteF = Worksheets("Spike Values").Cells(5, 1).Font.Color
- Color_Fail = Worksheets("Spike Values").Cells(6, 1).Interior.Color
- Color_FailF = Worksheets("Spike Values").Cells(6, 1).Font.Color
- ReDim LFMorig_address(1 To 50) As Range
- ReDim LFM_address(1 To 50) As Range
- ReDim LFM_List(1 To 50) As String
- ReDim LFM_Project(1 To 50) As String
- ReDim LFM_Number(1 To 50) As String
- ReDim Dilute_ListO(1 To 50) As String
- ReDim Dilute_ListD(1 To 50) As String
- ReDim TM_E(1 To 50) As Integer
- ReDim TM_I(1 To 50) As Integer
- TopRow = Top_Row(1)
- BottomRow = Top_Row(2)
- LFM_address = FindQC(2, 1, 0, 0)
- LFM_List = FindQC(2, 5, 0, 0)
- LFM_Project = FindQC(2, 3, 0, 0)
- LFM_Number = FindQC(2, 4, 0, 0)
- LFMorig_address = FindQC(2, 2, 0, 0)
- a_2 = 0
- 'For a = 1 To 50
- ' msgbox (LFM_address(a).Address)
- ' msgbox (LFMorig_address(a).Address)
- 'Next a
- For a = 1 To 50
- If LFM_address(a) <> Range("$A$1") And LFMorig_address(a) <> Range("$A$1") Then
- a_2 = a_2 + 1
- End If
- Next a
- For a = 1 To a_2
- Dilute_ListO(a) = Dilution(1, LFMorig_address(a))
- Dilute_ListD(a) = Dilution(1, LFM_address(a))
- TM_E(a) = TM_Check(LFM_address(a), 1)
- TM_I(a) = TM_Check(LFM_address(a), 0)
- Next a
- ReDim Preserve LFMorig_address(1 To a_2) As Range
- ReDim Preserve LFM_address(1 To a_2) As Range
- ReDim Preserve LFM_List(1 To a_2) As String
- ReDim Preserve LFM_Project(1 To a_2) As String
- ReDim Preserve LFM_Number(1 To a_2) As String
- ReDim Preserve Dilute_ListO(1 To a_2) As String
- ReDim Preserve Dilute_ListD(1 To a_2) As String
- ReDim Preserve TM_E(1 To a_2) As Integer
- ReDim Preserve TM_I(1 To a_2) As Integer
- Dilutions (2)
- For j_0 = 1 To 100
- If InStr(1, Cells(j_0, 1).Value, "RELATIVE PERCENT DIFFERENCE") <> 0 Then LastDUPRow = j_0
- Next j_0
- For a = 1 To a_2
- PercentRecoveryRow = LastDUPRow + a * 8
- If a > 2 Then
- Insert_LFM = (Trim(Str(PercentRecoveryRow - 6)) & ":" & Trim(Str(PercentRecoveryRow + 1)))
- Rows(Insert_LFM).Insert shift:=xlDown
- Rows(Insert_LFM).Interior.ColorIndex = xlNone
- Rows(Insert_LFM).Font.ColorIndex = xlblack
- Rows(Insert_LFM).NumberFormat = "General"
- Insert_LFM = (Trim(Str(PercentRecoveryRow - 6)) & ":" & Trim(Str(PercentRecoveryRow + 1)))
- Worksheets("Dilutions").Rows(Insert_LFM).Insert shift:=xlDown
- Worksheets("Dilutions").Rows(Insert_LFM).Interior.ColorIndex = xlNone
- Worksheets("Dilutions").Rows(Insert_LFM).Font.ColorIndex = xlblack
- Worksheets("Dilutions").Rows(Insert_LFM).NumberFormat = "General"
- Worksheets("Reset").Rows(17).Copy
- ActiveSheet.Paste Destination:=Worksheets("PSL").Rows(Str(PercentRecoveryRow - 2))
- ' Cells(PercentRecoveryRow - 9, 1).Copy
- Worksheets("Reset").Rows(18).Copy
- ActiveSheet.Paste Destination:=Worksheets("PSL").Rows(Str(PercentRecoveryRow - 1))
- ' Cells(PercentRecoveryRow - 8, 1).Copy
- Worksheets("Reset").Rows(19).Copy
- ActiveSheet.Paste Destination:=Worksheets("PSL").Rows(Str(PercentRecoveryRow))
- Rows(Str(PercentRecoveryRow)).Borders(xlEdgeBottom).Weight = xlMedium
- Rows(Str(PercentRecoveryRow + 2)).Borders(xlEdgeTop).Weight = xlThin
- Application.CutCopyMode = False
- Worksheets("Reset").Rows(13).Copy
- ActiveSheet.Paste Destination:=Worksheets("PSL").Rows(Str(PercentRecoveryRow - 6))
- TopRow = TopRow + 8
- BottomRow = BottomRow + 8
- End If
- If LFMorig_address(a).Value <> "" Then Cells(PercentRecoveryRow - 5, 1).Value = LFMorig_address(a).Value
- If LFM_address(a).Value <> "" Then Cells(PercentRecoveryRow - 4, 1).Value = LFM_address(a).Value
- ChangedLFMType = LFMSpike(a)
- Cells(PercentRecoveryRow, 1).Value = "PERCENT RECOVERY"
- Cells(PercentRecoveryRow, 1).Interior.Color = Color_Pass
- Cells(PercentRecoveryRow, 1).Font.Color = Color_PassF
- Rows(PercentRecoveryRow - 1).Interior.ColorIndex = xlNone
- Rows(PercentRecoveryRow - 2).Interior.ColorIndex = xlNone
- Cells(PercentRecoveryRow - 4, 1).Font.Bold = True
- Cells(PercentRecoveryRow - 4, 1).Font.Italic = False
- Cells(PercentRecoveryRow - 5, 1).Font.Bold = True
- Cells(PercentRecoveryRow - 5, 1).Font.Italic = False
- Cells(PercentRecoveryRow - 4, 1).Interior.ColorIndex = xlNone
- Cells(PercentRecoveryRow - 5, 1).Interior.ColorIndex = xlNone
- 'OrigVal = Cells(1, Range(LFMorig_address(a)).row).Value
- For c_1 = 2 To 100
- For c_2 = 2 To 70
- 'c_2 = 13
- 'c_1 = 15
- 'msgbox (Replace(Cells(1, c_2).Value, Space(1), Space(0)) & "'")
- 'msgbox (Replace(Left(Cells(TopRow, c_1), 2), Space(1), Space(0)) & "'")
- If Replace(Cells(1, c_2).Value, Space(1), Space(0)) = Replace(Left(Cells(TopRow, c_1), 2), Space(1), Space(0)) And Replace(Cells(1, c_2).Value, Space(1), Space(0)) <> "" Then
- Cells(PercentRecoveryRow, c_2).Interior.Color = Color_Pass
- Cells(PercentRecoveryRow, c_2).Font.Color = Color_PassF
- If Worksheets("Dilutions").Cells(LFMorig_address(a).Row, c_1) = 0 Then
- 'LFM_Value = Cells(i, m).Value
- ''Cells(PercentRecoveryRow - 1, c_2).Value = Cells(Application.Row(LFM_address(a)), c_1).Value
- Orig_Value = Cells(LFMorig_address(a).Row, c_1).Value
- Cells(PercentRecoveryRow - 5, c_2).Value = Orig_Value
- Cells(PercentRecoveryRow, c_2).Font.ColorIndex = vbBlack
- Cells(PercentRecoveryRow, c_2).Interior.Color = Color_Pass
- Cells(PercentRecoveryRow, c_2).Font.Color = Color_PassF
- 'End If
- 'Loop
- End If
- If Worksheets("Dilutions").Cells(LFMorig_address(a).Row, c_1) = 5 Then
- If Replace(Cells(1, c_2).Value, Space(1), Space(0)) = Left(Cells(TopRow, c_1 + 1), 2) And Worksheets("Dilutions").Cells(LFMorig_address(a).Row, c_1 + 1) = 5 Then
- 'Orig_Value = Application.Average(Cells(LFMorig_address(a).Row, c_1).Value, Cells(LFMorig_address(a).Row, c_1 + 1).Value)
- Cells(PercentRecoveryRow - 5, c_2).Value = "=AVERAGE(" & Cells(LFMorig_address(a).Row, c_1).Address & ", " & Cells(LFMorig_address(a).Row, c_1 + 1).Address & ")"
- Cells(PercentRecoveryRow + 1, 1).Font.Italic = True
- Cells(PercentRecoveryRow + 1, 1).Value = "Note: averaged concentration values indicated by cell coloring"
- Range(Cells(PercentRecoveryRow + 1, 1).Address & ":" & Cells(PercentRecoveryRow + 1, 4).Address).Interior.Color = Color_Accept
- Range(Cells(PercentRecoveryRow + 1, 1).Address & ":" & Cells(PercentRecoveryRow + 1, 4).Address).Font.Color = Color_AcceptF
- Cells(PercentRecoveryRow - 5, c_2).Interior.Color = Color_Accept
- Cells(PercentRecoveryRow - 5, c_2).Font.Color = Color_AcceptF
- Else:
- If Replace(Cells(1, c_2).Value, Space(1), Space(0)) = Left(Cells(TopRow, c_1 - 1), 2) And Worksheets("Dilutions").Cells(LFMorig_address(a).Row, c_1 - 1) = 5 Then
- 'Orig_Value = Application.Average(Cells(LFMorig_address(a).Row, c_1).Value, Cells(LFMorig_address(a).Row, c_1 - 1).Value)
- Cells(PercentRecoveryRow - 5, c_2).Value = "=AVERAGE(" & Cells(LFMorig_address(a).Row, c_1).Address & ", " & Cells(LFMorig_address(a).Row, c_1 - 1).Address & ")"
- Cells(PercentRecoveryRow + 1, 1).Font.Italic = True
- Cells(PercentRecoveryRow + 1, 1).Value = "Note: averaged concentration values indicated by cell coloring"
- Range(Cells(PercentRecoveryRow + 1, 1).Address & ":" & Cells(PercentRecoveryRow + 1, 4).Address).Interior.Color = Color_Accept
- Range(Cells(PercentRecoveryRow + 1, 1).Address & ":" & Cells(PercentRecoveryRow + 1, 4).Address).Font.Color = Color_AcceptF
- Cells(PercentRecoveryRow - 5, c_2).Interior.Color = Color_Accept
- Cells(PercentRecoveryRow - 5, c_2).Font.Color = Color_AcceptF
- End If
- End If
- 'LFM_Value = Cells(i, m).Value
- 'Cells(PercentRecoveryRow - 1, c_2).Value = Cells(Application.Row(LFM_address(a)), c_1).Value
- 'Orig_Value = Cells(j, m).Value
- 'Cells(PercentRecoveryRow - 2, c_2).Value = Cells(Application.Row(LFMorig_address(a)), c_1).Value
- 'Cells(PercentRecoveryRow, c_2).Font.ColorIndex = vbBlack
- 'Cells(PercentRecoveryRow, c_2).Interior.Color = Color_Pass
- 'Cells(PercentRecoveryRow, c_2).Font.Color = Color_PassF
- 'Average two numbers, then copy/paste
- ''Shade cell accordingly
- End If
- If Worksheets("Dilutions").Cells(LFMorig_address(a).Row, c_1) = 2 Or Worksheets("Dilutions").Cells(LFM_address(a).Row, c_1) = 2 Then
- Cells(PercentRecoveryRow, c_2).Value = "Dilute"
- Union(Range(Cells(PercentRecoveryRow, c_2).Address), Range(Cells(PercentRecoveryRow - 4, c_2).Address), Range(Cells(PercentRecoveryRow - 5, c_2).Address)).Interior.Color = Color_Dilute
- End If
- If Worksheets("Dilutions").Cells(LFMorig_address(a).Row, c_1) = 3 Then
- Orig_Value = Cells(LFMorig_address(a).Row, c_1).Value
- Cells(PercentRecoveryRow - 5, c_2).Value = Orig_Value
- For a_3 = 1 To a_2
- If LFM_Project(a) = LFM_Project(a_3) And LFM_Number(a) = LFM_Number(a_3) And TM_E(a) = TM_E(a_3) _
- And TM_I(a) = TM_I(a_3) And Worksheets("Dilutions").Cells(LFMorig_address(a_3).Row, c_1).Value = 2 _
- And a > a_3 And Dilute_ListO(a_3) < Dilute_ListO(a) Then
- For a_4 = 1 To a_2
- 'Checks if additional dilutions listed
- If LFM_Project(a) = LFM_Project(a_4) And LFM_Number(a) = LFM_Number(a_4) And TM_E(a) = TM_E(a_4) _
- And TM_I(a) = TM_I(a_4) And Worksheets("Dilutions").Cells(LFMorig_address(a_4).Row, c_1).Value = 2 _
- And a <> a_4 And a_3 <> a_4 And a <> a_3 And Dilute_ListO(a_3) <> Dilute_ListO(a) _
- And Dilute_ListO(a_4) <> Dilute_ListO(a) And Dilute_ListO(a_4) <> Dilute_ListO(a_3) Then
- Brine = 1
- 'msgbox ("BRINE=1 LFM_1")
- End If
- Next a_4
- If Brine <> 1 Then
- For a_5 = 1 To TopRow
- If InStr(1, Replace(LFM_List(a), Space(1), Space(0)), Replace(Cells(a_5, 1).Value, Space(1), Space(0))) <> 0 Then
- If Dilution(1, Range(Cells(a_5, 1).Address)) > Dilution(1, Range(Cells(a, 1).Address)) Then
- PercentRecoveryRow2 = a_5 + 4
- End If
- End If
- Next a_5
- 'PercentRecoveryRow2 = PercentRecoveryRow - Abs(8 * (a - a_3))
- Orig_Value = Cells(LFMorig_address(a).Row, c_1).Value
- Cells(PercentRecoveryRow2 - 5, c_2).Value = Orig_Value
- Cells(PercentRecoveryRow2 - 5, c_2).Interior.Color = Color_Dilute
- End If
- End If
- Next a_3
- 'Check FindQC string for same sample ID, number, TM, but different dilution factor
- 'If found, copy/paste alternate cell to destination, highlighting value in yellow
- 'If not found, highlight percent in yellow, write "dilute," and put "--" in destination cell
- End If
- If Worksheets("Dilutions").Cells(LFM_address(a).Row, c_1) = 0 Then
- LFM_Value = Cells(LFM_address(a).Row, c_1).Value
- Cells(PercentRecoveryRow - 4, c_2).Value = LFM_Value
- End If
- If Worksheets("Dilutions").Cells(LFM_address(a).Row, c_1) = 5 Then
- If Replace(Cells(1, c_2).Value, Space(1), Space(0)) = Left(Cells(TopRow, c_1 + 1), 2) And Worksheets("Dilutions").Cells(LFM_address(a).Row, c_1 + 1) = 5 Then
- 'LFM_Value = Application.Average(Cells(LFM_address(a).Row, c_1).Value, Cells(LFM_address(a).Row, c_1 + 1).Value)
- Cells(PercentRecoveryRow - 4, c_2).Value = "=AVERAGE(" & Cells(LFM_address(a).Row, c_1).Address & ", " & Cells(LFM_address(a).Row, c_1 + 1).Address & ")"
- Cells(PercentRecoveryRow + 1, 1).Font.Italic = True
- Cells(PercentRecoveryRow + 1, 1).Value = "Note: averaged concentration values indicated by cell coloring"
- Range(Cells(PercentRecoveryRow + 1, 1).Address & ":" & Cells(PercentRecoveryRow + 1, 4).Address).Interior.Color = Color_Accept
- Range(Cells(PercentRecoveryRow + 1, 1).Address & ":" & Cells(PercentRecoveryRow + 1, 4).Address).Font.Color = Color_AcceptF
- Cells(PercentRecoveryRow - 4, c_2).Interior.Color = Color_Accept
- Cells(PercentRecoveryRow - 4, c_2).Font.Color = Color_AcceptF
- Else:
- If Replace(Cells(1, c_2).Value, Space(1), Space(0)) = Left(Cells(TopRow, c_1 - 1), 2) And Worksheets("Dilutions").Cells(LFM_address(a).Row, c_1 - 1) = 5 Then
- 'LFM_Value = Application.Average(Cells(LFM_address(a).Row, c_1).Value, Cells(LFM_address(a).Row, c_1 - 1).Value)
- Cells(PercentRecoveryRow - 4, c_2).Value = "=AVERAGE(" & Cells(LFM_address(a).Row, c_1).Address & ", " & Cells(LFM_address(a).Row, c_1 - 1).Address & ")"
- Cells(PercentRecoveryRow + 1, 1).Font.Italic = True
- Cells(PercentRecoveryRow + 1, 1).Value = "Note: averaged concentration values indicated by cell coloring"
- Range(Cells(PercentRecoveryRow + 1, 1).Address & ":" & Cells(PercentRecoveryRow + 1, 4).Address).Interior.Color = Color_Accept
- Range(Cells(PercentRecoveryRow + 1, 1).Address & ":" & Cells(PercentRecoveryRow + 1, 4).Address).Font.Color = Color_AcceptF
- Cells(PercentRecoveryRow - 4, c_2).Interior.Color = Color_Accept
- Cells(PercentRecoveryRow - 4, c_2).Font.Color = Color_AcceptF
- End If
- End If
- End If
- If Worksheets("Dilutions").Cells(LFM_address(a).Row, c_1) = 3 Then
- LFM_Value = Cells(LFM_address(a).Row, c_1).Value
- Cells(PercentRecoveryRow - 4, c_2).Value = LFM_Value
- For a_3 = 1 To a_2
- If LFM_Project(a) = LFM_Project(a_3) And LFM_Number(a) = LFM_Number(a_3) And TM_E(a) = TM_E(a_3) _
- And TM_I(a) = TM_I(a_3) And Worksheets("Dilutions").Cells(LFM_address(a_3).Row, c_1).Value = 2 _
- And a > a_3 And Dilute_ListD(a_3) < Dilute_ListD(a) Then
- For a_4 = 1 To a_2
- 'Checks if additional dilutions listed
- If LFM_Project(a) = LFM_Project(a_4) And LFM_Number(a) = LFM_Number(a_4) And TM_E(a) = TM_E(a_4) _
- And TM_I(a) = TM_I(a_4) And Worksheets("Dilutions").Cells(LFM_address(a_4).Row, c_1).Value = 2 _
- And a <> a_4 And a_3 <> a_4 And a <> a_3 And Dilute_ListD(a_3) <> Dilute_ListD(a) _
- And Dilute_ListD(a_4) <> Dilute_ListD(a) And Dilute_ListD(a_4) <> Dilute_ListD(a_3) Then
- Brine = 1
- 'msgbox ("BRINE=1 LFM_2")
- End If
- Next a_4
- If Brine <> 1 Then
- 'PercentRecoveryRow2 = PercentRecoveryRow - Abs(4 * (a - a_3))
- For a_5 = 1 To TopRow
- If InStr(1, Replace(LFM_List(a), Space(1), Space(0)), Replace(Cells(a_5, 1).Value, Space(1), Space(0))) <> 0 Then
- If Dilution(1, Range(Cells(a_5, 1).Address)) > Dilution(1, Range(Cells(a, 1).Address)) Then
- PercentRecoveryRow2 = a_5 + 4
- End If
- End If
- Next a_5
- LFM_Value = Cells(LFM_address(a).Row, c_1).Value
- Cells(PercentRecoveryRow2 - 4, c_2).Value = LFM_Value
- Cells(PercentRecoveryRow2 - 4, c_2).Interior.Color = Color_Dilute
- 'Worksheets("Dilutions").Cells(LFM_address(a).Row, c_2) = 1
- If IsError(Cells(PercentRecoveryRow2, c_2)) = False Then
- If IsNumeric(Cells(PercentRecoveryRow2 - 4, c_2)) = True And IsNumeric(Cells(PercentRecoveryRow2 - 5, c_2)) = True And Cells(PercentRecoveryRow2 - 4, c_2).Value <> "" And Cells(PercentRecoveryRow2 - 5, c_2).Value <> "" Then
- If Len(Cells(1, c_1).Value) > 0 Then
- If IsNumeric(Cells(PercentRecoveryRow2, c_2).Value) = True Then
- If Abs(Cells(PercentRecoveryRow2, c_2).Value) < 1 Then Cells(PercentRecoveryRow2, c_2).NumberFormat = "0.00%"
- End If
- Cells(PercentRecoveryRow2, c_2).Font.ColorIndex = vbBlack
- Cells(PercentRecoveryRow2, c_2).Interior.Color = Color_Pass
- Cells(PercentRecoveryRow2, c_2).Font.Color = Color_PassF
- If InStr(1, Cells(PercentRecoveryRow2, c_2).Value, "Dilute") = 0 Or IsNumeric(Cells(PercentRecoveryRow2, c_2).Offset(-4, 0).Value) = False Or IsNumeric(Cells(PercentRecoveryRow2, c_2).Offset(-5, 0).Value) = False Then
- If Cells(PercentRecoveryRow2 - 1, c_2) < 0.3 * Cells(PercentRecoveryRow2 - 4, c_2) Then
- Cells(PercentRecoveryRow2, c_2).Interior.Color = Color_Accept
- Cells(PercentRecoveryRow2, c_2).Font.Color = Color_AcceptF
- Else:
- If Cells(PercentRecoveryRow2, c_2).Value <= 0.7 Or Cells(PercentRecoveryRow2, c_2).Value >= 1.3 Then
- Cells(PercentRecoveryRow2, c_2).Interior.Color = Color_Fail
- Cells(PercentRecoveryRow2, c_2).Font.Color = Color_FailF
- End If
- End If
- Else:
- Cells(PercentRecoveryRow2, c_2).Interior.Color = Color_Dilute
- Cells(PercentRecoveryRow2, c_2).Font.Color = Color_DiluteF
- End If
- End If
- End If
- End If
- Else:
- 'Brine subroutine for LFM calculations (If not covered in LFM Spike sub; otherwise, make simplified coloring routine here (one that doesn't paste dilutions twice))
- '
- '
- '
- '
- ' Entire code written by Omar Ali, 2016
- ' Updated 06.20.2018
- '
- '
- End If
- End If
- Next a_3
- End If
- If IsError(Cells(PercentRecoveryRow, c_2)) = False Then 'Delete all references to color below PercentRecoveryRow
- If InStr(1, Cells(PercentRecoveryRow, c_2).Value, "Dilute") = 0 Or IsNumeric(Cells(PercentRecoveryRow, c_2).Offset(-4, 0).Value) = False Or IsNumeric(Cells(PercentRecoveryRow, c_2).Offset(-5, 0).Value) = False Then
- If Cells(PercentRecoveryRow - 1, c_2) < 0.3 * Cells(PercentRecoveryRow - 4, c_2) Then
- Cells(PercentRecoveryRow, c_2).Interior.Color = Color_Accept
- Cells(PercentRecoveryRow, c_2).Font.Color = Color_AcceptF
- Else:
- If Cells(PercentRecoveryRow, c_2).Value <= 0.7 Or Cells(PercentRecoveryRow, c_2).Value >= 1.3 Then
- Cells(PercentRecoveryRow, c_2).Interior.Color = Color_Fail
- Cells(PercentRecoveryRow, c_2).Font.Color = Color_FailF
- End If
- End If
- Else:
- Cells(PercentRecoveryRow, c_2).Interior.Color = Color_Dilute
- Cells(PercentRecoveryRow, c_2).Font.Color = Color_DiluteF
- End If
- End If
- Exit For
- End If
- Next c_2
- If Cells(TopRow, c_1) = "" Then
- Exit For
- End If
- Next c_1
- Next a
- If ChangedLFMType = 1 Then
- msgbox ("Please confirm sample type (digest or direct) from dropdown menu")
- End If
- Application.EnableEvents = True
- End Sub
- Function Y_ISTD() As Integer
- Dim TopRow As Integer
- Dim BottomRow As Integer
- Dim ISTD(1 To 2) As String
- TopRow = Top_Row(1)
- BottomRow = Top_Row(2)
- ISTD(1) = Worksheets("Spike Values").Cells(5, 3).Value
- ISTD(2) = Worksheets("Spike Values").Cells(5, 4).Value
- Color_Pass = Worksheets("Spike Values").Cells(3, 1).Interior.Color
- Color_PassF = Worksheets("Spike Values").Cells(3, 1).Font.Color
- Color_Accept = Worksheets("Spike Values").Cells(4, 1).Interior.Color
- Color_AcceptF = Worksheets("Spike Values").Cells(4, 1).Font.Color
- Color_Dilute = Worksheets("Spike Values").Cells(5, 1).Interior.Color
- Color_DiluteF = Worksheets("Spike Values").Cells(5, 1).Font.Color
- Color_Fail = Worksheets("Spike Values").Cells(6, 1).Interior.Color
- Color_FailF = Worksheets("Spike Values").Cells(6, 1).Font.Color
- For m = 1 To 100
- If Replace(Left(Cells(TopRow, m).Value, 2), Space(1), Space(0)) = ISTD(1) Or Replace(Left(Cells(TopRow, m).Value, 2), Space(1), Space(0)) = ISTD(2) Then
- Exit For
- End If
- Next m
- If m = 101 Then
- msgbox ("Error in finding internal standard")
- Exit Function
- End If
- m = m + 1
- For j = TopRow + 2 To BottomRow
- If Cells(j, m).Value <= 0.8 Or Cells(j, m).Value >= 1.2 Then
- ' If Y 371.029 > 1.2 or Y 371.029 < 0.8 then highlight in red and (if applicable) include in error/report summary
- Cells(j, m).Interior.Color = Color_Fail
- Cells(j, m).Font.Color = Color_FailF
- Else:
- Cells(j, m).Interior.Color = Color_Pass
- Cells(j, m).Font.Color = Color_PassF
- End If
- Next j
- End Function
- Function Top_Row(P As Integer) As Integer
- If P = 1 Then
- 'Locate top row; end function
- For k = 1 To 500
- If InStr(1, Cells(k, 1).Value, "Sample Labels") <> 0 And InStr(1, Cells(k + 1, 1).Value, "Blank") <> 0 Then
- Top_Row = k
- k = 500
- End If
- Next k
- k = 1
- For k = 1 To 500
- If InStr(1, Cells(k, 1).Value, "Tube") <> 0 And InStr(1, Cells(k + 1, 1).Value, ":") <> 0 Then
- Top_Row = k
- With Range(Cells(Top_Row, 1).Address(False, False) & ":A500")
- .Delete
- End With
- Range(Cells(Top_Row - 1, 1).Address(False, False) & ":A500").HorizontalAlignment = xlLeft
- k = 500
- End If
- Next k
- End If
- '
- If P = 2 Then
- 'Locate bottom row; end function
- For k = 1 To 500
- If InStr(1, Cells(k, 1).Value, "Cont Calib Blank") <> 0 And InStr(1, Cells(k + 1, 1).Value, "Cont Calib Verif LO 10%") <> 0 And InStr(1, Cells(k + 2, 1).Value, "Cont Calib Verif HI 10%") <> 0 And (Cells(k + 10, 1).Value = "" Or Cells(k + 10, 1).Value = " ") Then
- k_1 = k
- Do While (InStr(1, Cells(k_1, 1).Value, "Cont Calib Blank") <> 0 Or InStr(1, Cells(k_1, 1).Value, "Cont Calib Verif LO 10%") <> 0 Or InStr(1, Cells(k_1, 1).Value, "Cont Calib Verif HI 10%") <> 0 Or Cells(k_1, 1).Value = "" Or Cells(k_1, 1).Value = " ") And k_1 < 500
- k_1 = k_1 + 1
- Loop
- If k_1 = 500 Then
- Top_Row = k + 2
- k = 500
- Else
- Top_Row = k_1
- Exit For
- End If
- End If
- Next k
- End If
- End Function
- Sub Reset()
- Application.EnableEvents = False
- Worksheets("Reset").Range("A1:AZ500").Copy
- Worksheets("PSL").Select
- ActiveSheet.Paste Destination:=Worksheets("PSL").Range("A1:AZ500")
- Application.CutCopyMode = False
- Worksheets("Dilutions").UsedRange.ClearContents
- Worksheets("Spike Values").Cells(3, 1).Interior.Color = RGB(146, 205, 220)
- Worksheets("Spike Values").Cells(3, 1).Font.Color = vbBlack
- Worksheets("Spike Values").Cells(4, 1).Interior.Color = RGB(217, 217, 225)
- Worksheets("Spike Values").Cells(4, 1).Font.Color = vbBlack
- Worksheets("Spike Values").Cells(5, 1).Interior.Color = RGB(255, 255, 150)
- Worksheets("Spike Values").Cells(5, 1).Font.Color = vbBlack
- Worksheets("Spike Values").Cells(6, 1).Interior.Color = RGB(255, 0, 0)
- Worksheets("Spike Values").Cells(6, 1).Font.Color = vbBlack
- Worksheets("Spike Values").Cells(2, 1).Font.Bold = False
- Application.EnableEvents = True
- End Sub
Add Comment
Please, Sign In to add comment