【问题标题】:Excel Vlookup macro with range and 2 workbooks具有范围和 2 个工作簿的 Excel Vlookup 宏
【发布时间】:2015-05-23 07:29:08
【问题描述】:

我想做一个宏来从填充的最后一行运行 vlookup。 下面的代码是得到最后被填充的行(J列)和最后被填充的行(A列),下面的公式就是得到这2列的最后一行;

Sub lookup()
'Find the last Row with data in a Column
'In this example we are finding the last row of column A (Filled) and J (to be filled)
    Dim lastRowA As Long
    Dim lastRowJ As Long
    With ActiveSheet
        lastRowA = .Cells(.Rows.Count, "A").End(xlUp).Row
        lastRowJ = .Cells(.Rows.Count, "J").End(xlUp).Row
    End With
    MsgBox lastRowA & "   " & lastRowJ

End Sub

vlookup 在列 C 中查找值,并在另一个 Excel 文件 C:\LINKED[Roster_Iloilo.xlsx]ACTIVE' 中查找范围! $C:$E。见File的图片 请在 vlookup 方面需要帮助。

【问题讨论】:

  • 如果您手动执行,公式会是什么样子?
  • =vlookup(C40846,'C:\LINKED[Roster_Iloilo.xlsx]ACTIVE'!$C:$E,3,0)

标签: vba excel


【解决方案1】:

这是你正在尝试的吗? (未经测试)

你可以写你的公式

"=vlookup(C40846,'C:\LINKED[Roster_Iloilo.xlsx]ACTIVE'!$C:$E,3,0)"

作为

"=vlookup(C" & "40846" & ",'C:\LINKED[Roster_Iloilo.xlsx]ACTIVE'!$C:$E,3,0)"

所以你所要做的就是替换最后一行:)

Sub Sample()
    Dim ws As Worksheet
    Dim lastRowA As Long
    Dim sFormulaPre As String
    Dim sFormulaSuff As String

    Set ws = ThisWorkbook.Sheets("Sheet1")

    '=vlookup(C40846,'C:\LINKED[Roster_Iloilo.xlsx]ACTIVE'!$C:$E,3,0)
    sFormulaPre = "=vlookup(C"
    sFormulaSuff = ",'C:\LINKED[Roster_Iloilo.xlsx]ACTIVE'!$C:$E,3,0)"

    With ws
        lastRowA = .Cells(.Rows.Count, "A").End(xlUp).Row

        MsgBox sFormulaPre & lastRowA & sFormulaSuff
        '~~> Usage
        '.Cells(1, 1).Formula = sFormulaPre & lastRowA & sFormulaSuff
    End With
End Sub

【讨论】:

  • 我运行它但没有填充从 40847 到 40854 的行:(
  • 您将公式放在哪里以及如何放置?
  • 我想在 J 列的最后一行 +1 到 A 列的最后一行的范围内计算公式。这将给我从 40847 到 40854 的范围。
  • 不,我的意思是你想把公式"=vlookup(C40846,'C:\LINKED[Roster_Iloilo.xlsx]ACTIVE'!$C:$E,3,0)"放在哪里?在哪个工作表和哪个单元格中?
  • Set ws = ThisWorkbook.Sheets("RAW") 已经对其进行了编辑,工作表名为 RAW
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-30
  • 1970-01-01
  • 2013-06-21
  • 1970-01-01
  • 2020-09-07
相关资源
最近更新 更多