小弟最近用 VBA 写了个程序,主要功能是把导入的数据(可能会很大)进行 摘选 和 四舍五入,首先,数据读入excel,当 第二列/第三列 >=3, 则保留此行,否则删除。下一步,文件Sa1 和 Sa2 进行排序,按照 m/z 从小到大,最后将m/z 四舍五入到一个数。 那位程序大牛人,可以帮我把程序写成 VB, 可以用界面窗口控制 数据读入 和一些简单参数的设定,小弟将感激不尽,感谢000次,愿磕头100 下。
m/z_Sa1    Intensity Noise                  m/z_sa2   Intensity  Noise239.1052   710921 181.12                 239.123   212342      222
477.2031   13232 187.59                 477.233   342432      188
226.9508   782117 180.66                 233.555   12333       321
 Sheets("raw_data").Select
Range("a1").Select
Dim A As Integer
Dim B As Long
Dim D, C As Long
NF1 = ActiveSheet.UsedRange.Rows.CountA = Sheets("raw_data").UsedRange.Columns.Count
B = Sheets("raw_data").UsedRange.Rows.Count
For D = 4 To (A / 2) + 2 Step 2
Cells(1, D - 1) = WorksheetFunction.Sum(Range(Cells(2, D - 2), Cells(65536, D - 2)))
    For C = 2 To B
    If Cells(C + 1, D - 2) = "" Then
    GoTo 64
ElseIf Cells(C, D - 2) / Cells(C, D) > 3 Or Cells(C, D - 2) / Cells(C, D) = 3 Then'Cells(C, D - 2) = Cells(C, D - 2) * Cells(1, D - 2) / Cells(1, D - 1)
Else
64 Cells(1, D - 2) = C
Range(Cells(C, D - 3), Cells(B, D)).Select
Selection.ClearRange(Columns(D - 3), Columns(D)).Select
Selection.Sort Key1:=Cells(2, D - 3), Order1:=xlAscending, Header:=xlYes, OrderCustom:=1, MatchCase:= _
        False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal, DataOption2 _
        :=xlSortNormalRange(Columns(D - 1), Columns(D)).Delete
GoTo 10
End If
Next C
10 Next D
Cells(1, 1).SelectCells(1, 2) = Cells(1, 1)
Cells(1, 1) = "Mass List"
Dim B1, E, D1, E1, G1, H1, I1 As Integer
Dim F1, A1, C1 As Long
B1 = Sheets("raw_data").UsedRange.Columns.Count
For D1 = 3 To B1 Step 2
  A1 = Sheets("raw_data").Columns(1).End(xlDown).Row
    For E1 = 2 To A1
         For C1 = 2 To A1
        If Cells(E1, 1) > Cells(C1, D1) - Cells(C1, D1) * 0.000002 And Cells(E1, 1) < Cells(C1, D1) + Cells(C1, D1) * 0.000002 Then
        Cells(E1, B1 + (0.5 * (D1 - 1))) = Cells(E1, B1 + (0.5 * (D1 - 1))) + Cells(C1, D1 + 1)
        Cells(C1, D1).Clear
        ElseIf Cells(E1, 1) < Cells(C1, D1) Then GoTo 61
        End If
        Next C1
61     Next E1
Range(Columns(D1), Columns(D1 + 1)).Sort Key1:=Cells(2, D1), Order1:=xlAscending, Header:=xlYes, OrderCustom:=1, MatchCase:= _
        False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal, DataOption2 _
        :=xlSortNormal
             F1 = Columns(D1).End(xlDown).Row
              If F1 = 65536 Then
        GoTo 62
        Else
        End If
        Range(Cells(2, D1), Cells(F1, D1)).Copy
                     Range(Cells(A1 + 1, 1), Cells(A1 + F1 - 1, 1)) = Range(Cells(2, D1), Cells(F1, D1))
        Cells(A1 + 1, 1).PasteSpecial
        Range(Cells(2, D1 + 1), Cells(F1, D1 + 1)).Copy
        Cells(A1 + 1, B1 + (0.5 * (D1 - 1))).PasteSpecial
62 Cells(1, B1 + (0.5 * (D1 - 1))) = Cells(1, D1)
    
 Next D1end sub
 如果可以做,我们可以在 msn: [email protected]