简体   繁体   English

用 vba Excel 过滤

[英]Filtering with vba Excel

Hello everybody i would really appreciate your help with the following problem:大家好,我非常感谢您对以下问题的帮助:

I have an Excel file that contains an hardware acquisition, with different sampling rate depending on the value (eg. some value acquiried at 100ms and others at 10ms in that case).我有一个包含硬件采集的 Excel 文件,根据值具有不同的采样率(例如,在这种情况下,某些值在 100 毫秒时获得,而其他值在 10 毫秒时获得)。 So i have the first column with Time value (every cell is 10ms) and the following columns with the other acquiried values.所以我有第一列时间值(每个单元格是 10 毫秒)和以下列与其他获取值。 Every column that corresponds to the 100ms acquisition frequency shows 10 blank cell after filled cell (while the 10ms ones are full).对应于 100ms 采集频率的每一列在填充单元格后显示 10 个空白单元格(而 10ms 的单元格已满)。 Now my question is: What's the best whay to filter all the values and create a new table with only value took every 1s?现在我的问题是:过滤所有值并创建一个只有值每 1 秒的新表的最佳方法是什么?
Thanks.谢谢。 Here's a screenshot (simplified)这是屏幕截图(简化)

Image of the file文件图片

文件图片

I would just use a couple of loops like this我只会使用几个这样的循环

Option Explicit

Sub CopySeconds()
    Dim FirstRow, LastRow, inRow, inCol, outRow, outCol, colShift As Variant
    LastRow = Cells(Rows.Count, "A").End(xlUp).Row
    FirstRow = 4
    outRow = FirstRow
    colShift = 10
    For inRow = FirstRow To LastRow
    If Not IsEmpty(Cells(inRow, 1)) And Int(Cells(inRow, 1)) = Cells(inRow, 1) Then
        For inCol = 1 To 4
        outCol = inCol + colShift
        Cells(outRow, outCol) = Cells(inRow, inCol)
        Next inCol
        outRow = outRow + 1
    End If
    Next inRow

End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM