【问题标题】:VBA Numeric Value Find / Overwrite dataVBA 数值查找/覆盖数据
【发布时间】:2018-06-13 20:47:12
【问题描述】:

我正在编写一个允许我每月更新数据的宏。但是,我意识到,有时我需要在对数据进行更正时覆盖同一个月的数据。我正在尝试提出一个宏,它允许我搜索整个列,如果与数据匹配,允许我运行另一个宏以用新数据覆盖旧数据。关于如何解决这个问题的任何想法?

这是我目前所拥有的。我需要将整个列替换为 i 到 500。

Sub FindMatchingValue()
Dim i As Integer, ValueToFind As Integer
intValueToFind = Sheet8.Range("L6")
For i = 1 To 500    ' This needs to be the entire column
    If Cells(i, 1).Value = intValueToFind Then
        MsgBox ("Found value on row " & i)
        Exit Sub
    End If
Next i

MsgBox ("Value not found in the range!")
End Sub

【问题讨论】:

  • 录制宏,然后在完成上述操作后查看您拥有的代码。
  • 我有代码的框架。我遇到的唯一问题是能够搜索整个列并将这些日期与另一张纸上的日期匹配。
  • 如果您有代码,请将其发布在您的问题中,突出显示哪个位不起作用。
  • 对不起

标签: vba excel


【解决方案1】:

您不想在整个列中运行循环(略超过 1 mil X)。相反,从底部找到最后一行,然后遍历该范围。

如果您的目标是在找到匹配项时运行第二个宏,您可以去掉 msgbox 和 Exit Sub 并替换为 Call SecondMacro,其中“SecondMacro”是您分配给您的子当然。只是一种选择~

Sub FindMatchingValue()

Dim i As Integer, ValueToFind As Integer, LRow as Integer
intValueToFind = Sheet8.Range("L6")

LRow = Range("A" & Rows.Count).End(XlUp).Row

For i = 1 To LRow
    If Cells(i, 1).Value = intValueToFind Then
        MsgBox ("Found value on row " & i)
        Exit Sub
    End If
Next i

MsgBox ("Value not found in the range!")
End Sub

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-14
    • 1970-01-01
    • 1970-01-01
    • 2023-02-02
    • 1970-01-01
    • 2018-04-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多