VBA运行时错误1004

VBA运行时错误1004,vba,excel,excel-2010,Vba,Excel,Excel 2010,我正在调试以以下错误消息结尾的VBA宏: Workbooks.OpenText Filename:=vCPath _ , Origin:=437, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _ xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, Semicolon:=False _ , Comma:=True, Space:=False, Other:=False, Fiel

我正在调试以以下错误消息结尾的VBA宏:

Workbooks.OpenText Filename:=vCPath _
, Origin:=437, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, Semicolon:=False _
, Comma:=True, Space:=False, Other:=False, FieldInfo:=Array(Array(1, 1), _
Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), Array(7, 1), Array(8, 1), _
Array(9, 1), Array(10, 1), Array(11, 1), Array(12, 1), Array(13, 1)), _
TrailingMinusNumbers:=True
“运行时错误'1004':

“找不到。检查文件名的拼写,并验证 文件位置是否正确

如果您试图从最近使用的文件列表中打开该文件,请确保该文件未重新命名、移动或删除。”

我检查了我没有使用删除/删除/重命名的文件,并且这些文件不是来自我最近的文件列表

触发错误消息的代码中有问题的部分:

Workbooks.OpenText Filename:=vCPath _
, Origin:=437, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, Semicolon:=False _
, Comma:=True, Space:=False, Other:=False, FieldInfo:=Array(Array(1, 1), _
Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), Array(7, 1), Array(8, 1), _
Array(9, 1), Array(10, 1), Array(11, 1), Array(12, 1), Array(13, 1)), _
TrailingMinusNumbers:=True
以下是所有代码:

' Changes to program to make
' Exclude outliers in average
' Develop fake data to at glance recognize whether program works.
' Source http://www.cpearson.com/excel/optimize.htm
' Declare .Filters
Option Explicit
Sub DataProcessingExperiment7()

On Error GoTo ErrorHandler
'   Declare as strings, as integers, as variants, decDecimals, as Office.FileDialog
Dim strPath, strFileN, strDirN, strRangeNOut, strRangeNIn, strFilename, strTLCorn, strBRCorn, strSelectedFile, strtemp_name As String
Dim vResMatrix(), vCPath, vFileN As Variant
Dim vRangeNOut, vRangeNIn, decInd6, decInd4, decInd5, decStep2, decMRow, decColIn, decInd3, decMcol As Double
Dim decMxRNo, decBgrSum, decRowIn, decInd, decM40eff, decStep, decColNo, decStartcol, decStartrow As Double
Dim decPlateNo, decMonoVal, decInd1, decEntryRow2, decEntryRow, decInd2, decBgrValP, decBgrRow As Double
Dim decBrgSum, decBgrVal, decRangeNIn, decRangeNOut, decTLCorn, decVolcorr, decBRCorn, decMEeff As Double
Dim decMediaVal, M40Eff, decMeanComp As Double
'   MEeff = measure of efflux due to crudely purified HDL in scintillation
'   Math operations are fastest with Integers / UIntegers: https://msdn.microsoft.com/en-us/library/ae55hdtk.aspx

'   Start File Explorer to select file containing data
Dim lngCount As Long
' Open the file dialog
With Application.FileDialog(msoFileDialogOpen)
    .AllowMultiSelect = True
    .Show

'   Display paths of each file selected
    For lngCount = 1 To .SelectedItems.Count
    Next lngCount
    For Each strFilename In .SelectedItems
        MsgBox strFilename
    Next
End With

'   Excel 2003 is a good filter choice: Excel Viewer, OpenOffice, + Excel versions can open these files
'   If .Show = - 1 user picked at least one file
    ' The user pressed cancel.
'   Assign strings to param locations from (1,2) to (7,2). This matches template
'   Now using relative references to increase portability and NOT SELECTING the cells to increase macro speed, shorten code
With ActiveCell
    .Offset(1, 2) = decPlateNo
    .Offset(2, 2) = decStartrow
    .Offset(3, 2) = decStartcol
    .Offset(4, 2) = decColNo
    .Offset(5, 2) = decStep
    .Offset(6, 2) = strDirN
    .Offset(7, 2) = strFileN
End With

'   Measure of efflux of 2 plates of scint-40
M40Eff = 4.37
M40Eff = 2.4

'   Select and copy data and range
Range("A1:O22").Select
Selection.Copy
MsgBox "start"
'   Use the array
For decInd = 1 To decPlateNo / 2 - 1
    decRowIn = 1 + decStep * 2 * decInd
    decRangeNIn = "A" + CStr(decRowIn)
    Range(decRangeNIn).Select
    ActiveSheet.Paste
Next decInd 'Go to next indice
Application.CutCopyMode = False ' Have the data in both sheets

Workbooks.OpenText Filename:=vCPath _
, Origin:=437, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, Semicolon:=False _
, Comma:=True, Space:=False, Other:=False, FieldInfo:=Array(Array(1, 1), _
Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), Array(7, 1), Array(8, 1), _
Array(9, 1), Array(10, 1), Array(11, 1), Array(12, 1), Array(13, 1)), _
TrailingMinusNumbers:=True

For decInd1 = 1 To decPlateNo 'Between these 2 columns
    decTLCorn = "B" + CStr(decStartrow + (decInd1 - 1) * decStep)
    decBRCorn = "M" + CStr(decStartrow + 7 + (decInd1 - 1) * decStep)
    decRangeNOut = decTLCorn + ":" + decBRCorn
    decRangeNIn = decTLCorn
    Windows(vFileN).Activate
    Range(vRangeNOut).Select
    Selection.Copy
    Windows(strtemp_name).Activate
    Sheets("Data").Select
    Range(vRangeNIn).Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
Next decInd1
'   Operation:=xlNone prevents calculations while pasting (less CPU intensive)
'   Don't skip blanks, don't transpose

'   Calculation of background and efflux for individual plates
For decInd1 = 1 To decPlateNo / 2
    decStep2 = (decInd1 - 1) * decStep * 2
    decBgrRow = decStartrow + 8 + decStep2
    decBgrValP = Cells(decBgrRow, 2).Value 'Background plate value
    For decInd2 = 0 To 7 'From column Ind2 to column 7 do multiplication
        decEntryRow = decStartrow + decInd2 + decStep2
        decEntryRow2 = decStartrow + decInd2 + decStep2 + 11
        decMediaVal = Cells(decEntryRow, 13).Value
        decMonoVal = Cells(decEntryRow2, 13).Value
        Cells(decEntryRow, 15).Value = decMEeff * 100 * decVolcorr * (decMediaVal - decBgrValP) / (decM40eff * decMonoVal + decVolcorr * decMEeff * (decMediaVal - decBgrValP))
    Next decInd2
Next decInd1
MsgBox "end"
'   calculation of average background for all media plates
decBgrSum = 0
For decInd1 = 1 To decPlateNo / 2
    decStep2 = (decInd1 - 1) * decStep * 2
    For decInd2 = 0 To 7
        decRowIn = decStartrow + decStep2 + decInd2
        decBgrSum = decBgrSum + Cells(decRowIn, 2).Value
    Next decInd2
Next decInd1
decBgrVal = decBgrSum / (4 * decPlateNo) 'The plates are split up into 4 (control (media) plates are 2 of them).
decBgrVal = Cells(2, 17).Value
'   Rearanging data and transferring to Results sheet
decMxRNo = 8 * decColNo
ReDim vResMatrix(1 To decMxRNo, 1 To decPlateNo)
Sheets("Data").Select
For decInd1 = 1 To decPlateNo
    decMcol = decInd1
    For decInd2 = 1 To 8
        decRowIn = (decInd1 - 1) * decStep + decStartrow + decInd2 - 1
        For decInd3 = 1 To decColNo
            decColIn = decStartcol + decInd3 - 1
            decMRow = (decInd3 - 1) * 8 + decInd2
            vResMatrix(decMRow, decMcol) = Cells(decRowIn, decColIn).Value
        Next decInd3
    Next decInd2
Next decInd1

Sheets("Results").Select
For decInd4 = 1 To decPlateNo
    For decInd5 = 1 To decMxRNo
        Cells(decInd5, decInd4).Value = vResMatrix(decInd5, decInd4) 'Put the values of the matrix in this range?
    Next decInd5
Next decInd4
Sheets("Results QC").Select
'   Select QC (quality control) calculation
Range("C81:C82").Select
Selection.Copy
For decInd = 1 To decPlateNo / 2 - 1
    decColIn = 2 + 2 * decInd + 1
    Cells(81, decColIn).Select
    ActiveSheet.Paste 'Paste values of the active sheet (C81:C82 range)
Next decInd

For decInd4 = 1 To decPlateNo
    decInd6 = decInd4 + 2
    For decInd5 = 1 To decMxRNo 'Put these cell values in the matrix
        Cells(decInd5, decInd6).Value = vResMatrix(decInd5, decInd4)
    Next decInd5
Next decInd4

For decInd4 = 1 To decPlateNo
decInd6 = decInd4 + 2
decMeanComp = 0.6 * Cells(81, decInd6).Value
For decInd5 = 1 To decMxRNo
    If Cells(decInd5, decInd6).Value < decMeanComp Then
    Cells(decInd5, decInd6).Interior.Color = RGB(255, 0, 0)
'           If the cell value is less than the average highlight them red as outliers. (More likely: from pipettes that didn't release)
    ElseIf Cells(decInd5, decInd6).Value > decMeanComp Then
    Cells(decInd5, decInd6).Interior.Color = RGB(7, 253, 56)
'           If the cell value is greater than the average highlight them green as outliers. (Unlikely unless )

    End If
Next decInd5
Next decInd4
MsgBox "4"
ErrorHandler:
MsgBox "Error Code" & Err.Number & vbNewLine & Err.Description, vbCritical, "Error Code" & Err.Number
End Sub
' Another function to continue arranging the data. Start by declaring all data types.
Sub Arrange_data()

On Error GoTo ErrorHandler

Dim strPath, strFileN, strDirN, strCPath, strRangeNOut, strRangeNIn, strTLCorn, strBRCorn As String
Dim decColIn4: decColIn4 = CDec(decColIn4)
Dim decInd5: decInd5 = CDec(decInd5)
Dim decInd6: decInd6 = CDec(decInd6)
Dim decPlateNo: decPlateNo = CDec(decPlateNo)
Dim decStartrow: decStartrow = CDec(decStartrow)
Dim decStartcol: decStartcol = CDec(decStartcol)


Sheets("Parameters").Select
decPlateNo = Cells(1, 2).Value
decStartrow = Cells(2, 2).Values
decStartcol = Cells(3, 2).Value
decColNo = Cells(4, 2).Value
decStep = Cells(5, 2).Value
decMEeff = 2.03
decM40eff = 4.37 'microscint 40=kind of solution the macrophages go in
decVolcorr = 2.4
decMxRNo = 8 * decColNo
ReDim vResMatrix(1 To decMxRNo, 1 To decPlateNo)

'   Select QC (quality control) data
Sheets("Results QC").Select
For decInd1 = 1 To decPlateNo
    decInd3 = decInd1 + 2
    For decInd2 = 1 To iMxRNo
        vResMatrix(decInd2, decInd1) = Cells(decInd2, decInd3).Value
    Next decInd2
Next decInd1
'   Transfer data for two methods of efflux calculations.
'   Create template of columns.
Sheets("Processed indiv").Select
Range("C2:E87").Select
Selection.Copy
For decInd = 1 To decPlateNo / 2 - 1
    decColIn = 3 + 3 * decInd
    Cells(2, decColIn).Select
    ActiveSheet.Paste
Next decInd
Application.CutCopyMode = False
'   Don't cut and copy: leave the values in the Excel sheet.
'    For disgorging values stored in matrix and calculate efflux.
For decInd1 = 1 To decPlateNo / 2
    decColIn1 = 3 + 3 * (decInd1 - 1)
    decColIn2 = decColIn1 + 1
    decColIn3 = decColIn1 + 2
    decBgrRow = (decInd1 - 1) * decStep * 2 + decStartrow + 8
    decInd4 = 2 * decInd1
    decInd3 = decInd4 - 1
    Cells(1, decStartcol + 3 * (decInd1 - 1)).Value = "Plate " + CStr(decInd1)
'       Get background value for the plate.
    Sheets("Data").Select
    decBgrValP = Cells(decBgrRow, 2)
    Sheets("Processed indiv").Select
'       Digorging values and calculating efflux.
    For decInd2 = 1 To iMxRNo
        decMediaVal = vResMatrix(decInd2, decInd3)
        decMonoVal = vResMatrix(decInd2, decInd4)
        Cells(2 + decInd2, decColIn1).Value = decMediaVal
        Cells(2 + decInd2, decColIn2).Value = decMonoVal
        Cells(2 + decInd2, decColIn3).Value = decMEeff * 100 * decVolcorr * (decMediaVal - decBgrValP) / (decM40eff * decMonoVal + decVolcorr * decMEeff * (decMediaVal - decBgrValP))
    Next decInd2
Next decInd1
'   Remove no data cells.
For decInd1 = 1 To decPlateNo / 2
    decColIn1 = 3 + 3 * (decInd1 - 1)
    For decInd2 = 3 To decMxRNo + 2
        If Cells(decInd2, decColIn1).Value = "" Then
            Cells(decInd2, decColIn1 + 1).Value = ""
            Cells(decInd2, decColIn1 + 2).Value = ""
        End If
    Next decInd2
Next decInd1
'   calculate data based on plate average.
'   Create template for columns.
Sheets("Processed by plate").Select
Range("C2:E87").Select
Selection.Copy
For decInd = 1 To decPlateNo / 2 - 1
    decColIn = 3 + 3 * decInd
    Cells(2, decColIn).Select
    ActiveSheet.Paste
Next decInd
Application.CutCopyMode = False
'   Prep for disgorging values stored in matrix and calculate efflux.
For decInd1 = 1 To decPlateNo / 2
    decColIn1 = 3 + 3 * (decInd1 - 1)
    decColIn2 = decColIn1 + 1
    decColIn3 = decColIn1 + 2
    decBgrRow = (decInd1 - 1) * decStep * 2 + decStartrow + 8
    decInd4 = 2 * decInd1
    decInd3 = decInd4 - 1
    Cells(1, decStartcol + 3 * (decInd1 - 1)).Value = "Plate " + CStr(decInd1)
'       Get background value for the plate.
    Sheets("Data").Select
    decBgrValP = Cells(decBgrRow, 2)
    Sheets("Processed by plate").Select
'       Digorging values and calculating efflux.
'       When does this for loop end?
    For decInd2 = 1 To decMxRNo
        Cells(2 + decInd2, decColIn1).Value = vResMatrix(decInd2, decInd3)
        Cells(2 + decInd2, decColIn2).Value = vResMatrix(decInd2, decInd4)
    Next decInd2
'       Get average value for monolayer. (Cells are in 1-cell deep layer.) ?
    decMonoVal = Cells(83, decColIn2).Value
    For decInd2 = 1 To decMxRNo
        decMediaVal = vResMatrix(decInd2, decInd3)
        Cells(2 + decInd2, decColIn3).Value = decMEeff * 100 * decVolcorr * (decMediaVal - decBgrValP) / (decM40eff * decMonoVal + decVolcorr * decMEeff * (decMediaVal - decBgrValP))
    Next decInd2
Next decInd1
'   Remove no data cells.
For decInd1 = 1 To decPlateNo / 2
    decColIn1 = 3 + 3 * (decInd1 - 1)
    For decInd2 = 3 To decMxRNo + 2
        If Cells(decInd2, decColIn1).Value = "" Then
            Cells(decInd2, decColIn1 + 1).Value = ""
            Cells(decInd2, decColIn1 + 2).Value = ""
        End If
    Next decInd2
Next decInd1
'   Replace cell count data with calculated efflux in the matrix.
Sheets("Processed indiv").Select
For decInd1 = 1 To decPlateNo / 2
    decColIn1 = 5 + 3 * (decInd1 - 1)
    decInd4 = 2 * decInd1
    For decInd2 = 1 To decMxRNo
        vResMatrix(decInd2, decInd4) = Cells(2 + decInd2, decColIn1).Value
    Next decInd2
Next decInd1
'Move data to duplicate comparison.
Sheets("Duplicate comparison").Select
Range("C2:N87").Select
Selection.Copy
For decInd = 1 To decPlateNo / 4 - 1
    decColIn = 3 + 12 * decInd
    Cells(2, decColIn).Select
    ActiveSheet.Paste
Next decInd
Application.CutCopyMode = False
For decInd1 = 1 To decPlateNo / 4
    decColIn1 = 3 + 12 * (decInd1 - 1)
    decColIn2 = decColIn1 + 2
    decColIn3 = decColIn1 + 3
    decColIn4 = decColIn1 + 5
    decInd3 = decInd1 * 4 - 3
    decInd4 = decInd3 + 1
    decInd5 = decInd3 + 2
    decInd6 = decInd3 + 3
    Cells(1, decStartcol + 12 * (decInd1 - 1)).Value = "Plate " + CStr(2 * decInd1 - 1)
    Cells(1, decStartcol + 3 + 12 * (decInd1 - 1)).Value = "Plate " + CStr(2 * decInd1)
    For iInd2 = 1 To iMxRNo
        Cells(2 + iInd2, iColIn1).Value = vResMatrix(decInd2, decInd3)
        Cells(2 + iInd2, iColIn2).Value = vResMatrix(decInd2, decInd4)
        Cells(2 + iInd2, iColIn3).Value = vResMatrix(decInd2, decInd5)
        Cells(2 + iInd2, iColIn4).Value = vResMatrix(decInd2, decInd6)
    Next decInd2
Next decInd1
'   Remove no data cells.
For decInd1 = 1 To decPlateNo / 4
    decColIn1 = 3 + 12 * (decInd1 - 1)
    decColIn2 = decColIn1 + 3
    For decInd2 = 3 To decMxRNo + 2
        If Cells(decInd2, decColIn1).Value = "" Then
        Cells(decInd2, decColIn1 + 1).Value = ""
        For decInd = 1 To 6
            Cells(decInd2, decColIn1 + 5 + decInd).Value = ""
        Next decInd
        End If
If Cells(decInd2, decColIn2).Value = "" Then
    Cells(decInd2, decColIn2 + 1).Value = ""
    For decInd = 1 To 6
        Cells(decInd2, decColIn2 + 2 + decInd).Value = ""
    Next iInd
End If
Next decInd2
Next decInd1
'   Prepare summary statistics.
decTL = decPlateNo * decMxRNo / 2
ReDim vResMatrix(1 To 4, 1 To iTL)
Sheets("Processed indiv").Select
decRowIn = 3 + decMxRNo
decRowIn2 = decRowIn + 1
For decInd1 = 1 To 3 * decPlateNo / 2
    For decInd2 = 1 To 3
        decRowIn3 = 3 * (decInd1 - 1) + iInd2
        decColIn = 2 + decRowIn3
        vResMatrix(1, decRowIn3) = Cells(decRowIn, decColIn).Value
        vResMatrix(2, decRowIn3) = Cells(decRowIn2, decColIn).Value
    Next decInd2
Next decInd1
Sheets("Processed by plate").Select
decRowIn = 3 + iMxRNo
decRowIn2 = decRowIn + 1
For decInd1 = 1 To 3 * decPlateNo / 2
    For decInd2 = 1 To 3
        decRowIn3 = 3 * (decInd1 - 1) + decInd2
        decColIn = 2 + decRowIn3
        vResMatrix(3, iRowIn3) = Cells(decRowIn, decColIn).Value
        vResMatrix(4, decRowIn3) = Cells(decRowIn2, decColIn).Value
    Next decInd2
Next decInd1
'   Put summary statistics in distribution comp.
Sheets("Distribution comp").Select
For decInd = 1 To 3 * decPlateNo / 2
    Cells(2 + iInd, 2).Value = vResMatrix(1, iInd)
    Cells(2 + iInd, 3).Value = vResMatrix(2, iInd)
    Cells(2 + iInd, 5).Value = vResMatrix(3, iInd)
    Cells(2 + iInd, 6).Value = vResMatrix(4, iInd)
Next decInd
'   Prepare plate by plate results.
Sheets("Duplicate comparison").Select
For decInd = 1 To iPlateNo / 4
    decMatrixStep = (iInd - 1) * iMxRNo
    decColIn = 9 + 12 * (iInd - 1)
    decColIn2 = iColIn + 2
    decColIn3 = iColIn + 1
    decColIn4 = iColIn + 3
    For decInd2 = 1 To decMxRNo
        decMRow = iMatrixStep + decInd2
'           Difference between duplicates converted into range.
        vResMatrix(1, iMRow) = Cells(2 + decInd2, decColIn).Value
        vResMatrix(2, iMRow) = Cells(2 + decInd2, decColIn2).Value / 2
        vResMatrix(3, iMRow) = Cells(2 + decInd2, decColIn3).Value
        vResMatrix(4, iMRow) = Cells(2 + decInd2, decColIn4).Value / 2
    Next decInd2
Next decInd
'   Transfer data to Summary.
Sheets("Summary").Select
'   Prepare sheet.
Range("B3:G82").Select
Selection.Copy
For decInd = 1 To decPlateNo / 4 - 1
    decRowIn = 3 + decMxRNo * iInd
    decRangeNIn = "B" + CStr(decRowIn)
    Range(decRangeNIn).Select
    ActiveSheet.Paste
    For decInd2 = 1 To decMxRNo
        Cells(decInd2 + decRowIn - 1, 1).Value = "Plate " + CStr(decInd + 1)
    Next decInd2
Next decInd
Application.CutCopyMode = False
'   Don't cut and copy
'   Distribute values.
For decInd = 1 To decTL
    iRowIn = iInd + 2
    Cells(decRowIn, 4).Value = vResMatrix(1, decInd)
    Cells(decRowIn, 5).Value = vResMatrix(2, decInd)
    Cells(decRowIn, 6).Value = vResMatrix(3, decInd)
    Cells(decRowIn, 7).Value = vResMatrix(4, decInd)
Next decInd
'   Transfer data to Matrix summary.
Sheets("Matrix summary").Select
'   Prepare page for data.
Range("A1:M11").Select
Selection.Copy
For decInd = 1 To decPlateNo / 4 - 1
    decRowIn = 1 + decStep * decInd
    decRangeNIn = "A" + CStr(decRowIn)
    Range(decRangeNIn).Select
    ActiveSheet.Paste
Next decInd
Application.CutCopyMode = False
'   Distribute data.
For decInd1 = 0 To iPlateNo / 4 - 1
    decPlateStep = decStep * decInd1
    decMatrixStep = iColNo * 8 * decInd1
    For decInd2 = 0 To iColNo - 1
        decColIn = decStartcol + decInd2
        decColStep = 8 * iInd2
        For iInd3 = 0 To 7
            iRowIn = iStartrow + iPlateStep + iInd3
            iMxElem = iMatrixStep + iColStep + iInd3 + 1
            Cells(decRowIn, decColIn).Value = vResMatrix(3, iMxElem)
        Next decInd3
    Next decInd2
Next decInd1
'   collect statistical parameters on efflux for unknown samples.
decRowNo = decPlateNo / 4
ReDim decEffluxMatrix(1 To iRowNo, 1 To 6)
decStartRowIn = 10
decStartColIn = 2
For decInd = 0 To iRowNo - 1
    decRowIn = iStartRowIn + iStep * iInd
    EffluxMatrix(iInd + 1, 1) = Cells(iRowIn, iStartColIn).Value
    EffluxMatrix(iInd + 1, 2) = Cells(iRowIn + 1, iStartColIn).Value
Next decInd
'collect statistical parameters on efflux for control samples.
Sheets("Data").Select
decStartRowIn = 10
decStartColIn = 15
For iInd = 0 To iRowNo - 1
    iRowIn = iStartRowIn + iStep * iInd * 4
    EffluxMatrix(iInd + 1, 3) = Cells(iRowIn, iStartColIn).Value
    EffluxMatrix(iInd + 1, 4) = Cells(iRowIn + 1, iStartColIn).Value
    EffluxMatrix(iInd + 1, 5) = Cells(iRowIn + 22, iStartColIn).Value
    EffluxMatrix(iInd + 1, 6) = Cells(iRowIn + 23, iStartColIn).Value
Next decInd
'   Ouput of statistical parameters on efflux
Sheets("Matrix summary").Select
decStartRowOut = 4
decStartColOut = 15
For decInd1 = 1 To decRowNo
    decRowOut = decStartRowOut + decInd1 - 1
    For decInd2 = 1 To 6
        decColOut = decStartColOut + decInd2 - 1
        Cells(decRowOut, decColOut).Value = EffluxMatrix(decInd1, decInd2)
    Next iInd2
Next decInd1
'Output into Matrix min-max
Sheets("Matrix min-max").Select
For decInd1 = 0 To decPlateNo / 4 - 1
    decPlateStep = decStep * decInd1
    decMatrixStep = decColNo * 8 * decInd1
    For decInd2 = 0 To decColNo - 1
        decColIn = decStartcol + iInd2
        decColStep = 8 * decInd2
        For decInd3 = 0 To 7
            decRowIn = decStartrow + decPlateStep + decInd3
            decMxElem = decMatrixStep + decColStep + decInd3 + 1
            Cells(decRowIn, decColIn).Value = vResMatrix(3, decMxElem)
        Next decInd3
    Next decInd2
Next decInd1

ErrorHandler:
MsgBox "Error detected" & vbNewLine & "Error" & Err.Number & ": " & Err.Description, vbCritical, "Error Handler: Error " & Err.Number
MsgBox "If you want to force the program to run, go to the line below and insert a ' mark to comment the line out." & vbNewLine & "On Error GoTo ErrorHandler", vbCritical, "Error Handler: Error " & Err.Number
End Sub
”要进行的程序更改
'平均排除异常值
“开发虚假数据,以便一目了然地识别程序是否有效。
"来源:http://www.cpearson.com/excel/optimize.htm
'Declare.Filters
选项显式
子数据处理实验7()
关于错误转到错误处理程序
'声明为字符串、整数、变量、十进制数、Office.FileDialog
Dim strPath、strFileN、strDirN、strRangeNOut、strRangeNIn、strFilename、strTLCorn、strBRCorn、strSelectedFile、strtemp\u name作为字符串
Dim vResMatrix(),vCPath,vFileN作为变体
尺寸Vrangenut、vRangeNIn、Decind 6、Decind 4、Decind 5、decStep2、decMRow、decColIn、Decind 3、decMcol为双精度
尺寸decMxRNo、decBgrSum、decRowIn、decInd、decM40eff、decStep、decColNo、decStartcol、decStartrow为双精度
Dim decPlateNo、decMonoVal、decInd1、DECITRYROW2、DECITRYROW、decInd2、decBgrValP、decBgrRow为双精度
Dim decBrgSum、decBgrVal、Decangenin、Decangenout、decTLCorn、decVolcorr、decBRCorn、decMEeff为双精度
Dim DECEMIDIVAL,M40Eff,DECEMEANCOMP为双精度
'MEeff=闪烁中未经纯化的HDL导致的流出量测量
'整数/u整数的数学运算最快:https://msdn.microsoft.com/en-us/library/ae55hdtk.aspx
'启动文件资源管理器以选择包含数据的文件
暗计数等于长
'打开文件对话框
使用Application.FileDialog(msoFileDialogOpen)
.AllowMultiSelect=True
显示
'显示每个选定文件的路径
对于lngCount=1到。选择EditEMS.Count
下一个lngCount
对于中的每个strFilename。选择EditEMS
MsgBox strFilename
下一个
以
“Excel 2003是一个很好的过滤器选择:Excel Viewer、OpenOffice、+Excel版本可以打开这些文件
'If.Show=-1用户至少选择了一个文件
'用户按了“取消”。
'将字符串分配到从(1,2)到(7,2)的参数位置。这与模板匹配
现在使用相对引用来提高可移植性,而不是选择单元格来提高宏速度,缩短代码
使用ActiveCell
.偏移量(1,2)=decPlateNo
.偏移量(2,2)=decStartrow
.偏移量(3,2)=decStartcol
.偏移量(4,2)=decColNo
.偏移量(5,2)=退步
.偏移量(6,2)=标准偏差
.偏移量(7,2)=strFileN
以
'测量scint-40两个平板的流出量
M40Eff=4.37
M40Eff=2.4
'选择并复制数据和范围
范围(“A1:O22”)。选择
选择,复制
MsgBox“开始”
'使用数组
对于decInd=1到DecPlate No/2-1
decRowIn=1+decStep*2*decInd
decRangeNIn=“A”+CStr(decRowIn)
范围(减小范围)。选择
活动表。粘贴
下一个决策转到下一个指标
Application.CutCopyMode=False“在两张表中都有数据
Workbooks.OpenText文件名:=vCPath_
,Origin:=437,StartRow:=1,数据类型:=xlDelimited,TextQualifier:=_
xlDoubleQuote,连续delimiter:=False,制表符:=False,分号:=False_
,逗号:=真,空格:=假,其他:=假,字段信息:=数组(数组(1,1)_
数组(2,1)、数组(3,1)、数组(4,1)、数组(5,1)、数组(6,1)、数组(7,1)、数组(8,1)_
数组(9,1)、数组(10,1)、数组(11,1)、数组(12,1)、数组(13,1))_
TrailingMinusNumbers:=真
对于这两列之间的decInd1=1到decPlateNo'
decTLCorn=“B”+CStr(decStartrow+(decInd1-1)*decStep)
decBRCorn=“M”+CStr(decStartrow+7+(decInd1-1)*decStep)
decangenout=decTLCorn+“:”+decBRCorn
decRangeNIn=decTLCorn
Windows(vFileN)。激活
范围(vRangeNOut)。选择
选择,复制
Windows(strtemp\u名称)。激活
工作表(“数据”)。选择
范围(vRangeNIn)。选择
Selection.Paste特殊粘贴:=xlPasteValues,操作:=xlNone,SkipBlank_
:=假,转置:=假
下一个决定1
'操作:=xlNone禁止粘贴时进行计算(CPU占用较少)
“不要跳过空格,不要转置
'单个板的背景和流出计算
对于decInd1=1到DecPlate No/2
decStep2=(decInd1-1)*decStep2
Decbgrow=decStartrow+8+decStep2
decBgrValP=单元格(DECBGROW,2)。值“背景板值”
对于从Ind2列到第7列的decInd2=0到7',执行乘法
decEntryRow=decStartrow+decInd2+decStep2
decEntryRow2=decStartrow+decInd2+decStep2+11
decMediaVal=单元格(decEntryRow,13)。值
decMonoVal=单元格(decEntryRow2,13)。值
单元格(decEntryRow,15)。值=decMEeff*100*decVolcorr*(decMediaVal-decBgrValP)/(decM40eff*decMonoVal+decVolcorr*decMEeff*(decMediaVal-decBgrValP))
下一个决定2
下一个决定1
MsgBox“结束”
'计算所有介质板的平均背景
decBgrSum=0
对于decInd1=1到DecPlate No/2
decStep2=(decInd1-1)*decStep2
对于decInd2=0到7
decRowIn=decStartrow+decStep2+decInd2
decBgrSum=decBgrSum+单元格(decRowIn,2)。值
下一个决定2
下一个决定1
decBgrVal=decBgrSum/(4*decPlateNo)'板被分成4块(对照(介质)板是其中的2块)。
decBgrVal=单元格(2,17).值
'重新调整数据范围并传输到结果表
decMxRNo=8*decColNo
ReDim vResMatrix(1至decMxRNo,1至decMxRNo)
工作表(“数据”)。选择
对于decInd1=1到DecPlate No
decMcol=decInd1
对于decInd2=1到8
decRowIn=(decInd1-1)*decStep+decStartrow+decInd2-1
对于decInd3=1到decColNo
decColIn=decStartcol+decInd3-