【问题标题】:VBA code to remove a set of words from column E and highlight the same set of words in column DVBA 代码从 E 列中删除一组单词并突出显示 D 列中的同一组单词
【发布时间】:2013-07-30 15:34:11
【问题描述】:

我对 Excel 和 VBA 比较陌生,我一直在编写一个代码,我想从 E 列中删除一组单词,并且我需要在 D 列中突出显示相同的一组单词;

运行宏之前的列

D 列

红色
蓝天
绿色火箭

E 列

红色
蓝天
绿色火箭

在使用一组单词(红色、蓝色、绿色)运行宏的列之后

D 列

红色颜色
蓝色天空
绿色火箭

E 列

颜色
天空
火箭

我已经录制了宏并且一直在使用查找和替换语句。问题是我拥有的行数约为 20,000 到 30,000 。所以我需要宏尽快高效地工作。任何帮助将不胜感激。

【问题讨论】:

    标签: vba excel excel-2010


    【解决方案1】:

    鉴于您正在处理大量行,我首先建议您编写自己的宏而不是尝试记录一个宏。我将首先编写一个带有基本 For 循环的子例程,该循环访问您感兴趣的列中的每一行。

    Dim i as long
    Dim j as long
    Dim finalRowEColumn as long
    Dim finalRowDColumn as long
    Dim eCellValue as string
    
    finalRow = <Insert your final row here, or dynamically get it from your range of rows>
    For i = 1 to finalRowEColumn
        eCellValue = Range("E" & i).Value
        For j = 1 to finalRowDColumn
            dCellValue = Range("D" & j).Value
            'This inner loop will allow you do perform comparisons with the values in each of the columns
            'You may set cell formats, values, etc. Depending on your parameters eCellValue and dCellValue.
        Next j
    Next i
    

    我希望这是一个好的开始。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-07-07
      • 1970-01-01
      • 1970-01-01
      • 2013-08-25
      • 1970-01-01
      • 2013-07-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多