尝试解析CSV文件 - 添加新数据

时间:2022-05-15 06:39:18

I'm trying to parse through a large data set in Excel.

我正在尝试解析Excel中的大型数据集。

Here is my example data

这是我的示例数据

2 个解决方案

#1


0  

Asking for code and not posting any is an off topic reason here but with Record Macro the following might suit, assuming election is in ColumnA and starts in Row1:

询问代码而不发布任何代码是一个偏离主题的原因,但是使用Record Macro以下可能适合,假设选举在ColumnA中并在Row1中开始:

in B2 (inserted column) and copied down to suit: =IF(A1="election",B1+1,B1)
in C1 (inserted column) and copied down to suit: =IF(A1="V",A1&B1,IF(A1="election",A1,""))

在B2(插入列)中并向下复制以适应:= IF(A1 =“选举”,B1 + 1,B1)在C1(插入列)中并向下复制以适应:= IF(A1 =“V”,A1和B1, IF(A1 = “选举”,A1, “”))

Select sheet, Copy, Paste Special..., Values, delete ColumA:B.

选择工作表,复制,选择性粘贴...,值,删除ColumA:B。

#2


0  

Option Explicit
Option Compare Text
Sub ElectionID()
    Dim r As Range
    Dim I As Long, J As Long
Set r = Range("a1", Cells(Rows.Count, "A").End(xlUp))
For I = 1 To r.Rows.Count
    Select Case r(I)
        Case Is = "election"
            J = J + 1
        Case Is = "V"
            r(I) = "V" & J
    End Select
Next I
End Sub

If you have a large number of these, and the macro is taking a long time, we can do things like turn off screen updating, and also do the work in VBA arrays instead of on the worksheet. But I'm keeping this simple initially.

如果你有大量这些,并且宏需要很长时间,我们可以做一些事情,比如关闭屏幕更新,还可以在VBA数组中而不是在工作表上进行工作。但我最初保持这个简单。

#1


0  

Asking for code and not posting any is an off topic reason here but with Record Macro the following might suit, assuming election is in ColumnA and starts in Row1:

询问代码而不发布任何代码是一个偏离主题的原因,但是使用Record Macro以下可能适合,假设选举在ColumnA中并在Row1中开始:

in B2 (inserted column) and copied down to suit: =IF(A1="election",B1+1,B1)
in C1 (inserted column) and copied down to suit: =IF(A1="V",A1&B1,IF(A1="election",A1,""))

在B2(插入列)中并向下复制以适应:= IF(A1 =“选举”,B1 + 1,B1)在C1(插入列)中并向下复制以适应:= IF(A1 =“V”,A1和B1, IF(A1 = “选举”,A1, “”))

Select sheet, Copy, Paste Special..., Values, delete ColumA:B.

选择工作表,复制,选择性粘贴...,值,删除ColumA:B。

#2


0  

Option Explicit
Option Compare Text
Sub ElectionID()
    Dim r As Range
    Dim I As Long, J As Long
Set r = Range("a1", Cells(Rows.Count, "A").End(xlUp))
For I = 1 To r.Rows.Count
    Select Case r(I)
        Case Is = "election"
            J = J + 1
        Case Is = "V"
            r(I) = "V" & J
    End Select
Next I
End Sub

If you have a large number of these, and the macro is taking a long time, we can do things like turn off screen updating, and also do the work in VBA arrays instead of on the worksheet. But I'm keeping this simple initially.

如果你有大量这些,并且宏需要很长时间,我们可以做一些事情,比如关闭屏幕更新,还可以在VBA数组中而不是在工作表上进行工作。但我最初保持这个简单。