在VBA中从A2删除行到列的末尾

时间:2018-06-06 20:30:11

标签: vba excel-vba excel

我试图在VBA中提出一个代码,将从A2(第2行)删除到行尾

data = {
  "Agent Contribution (Incl Rev)": {
    "Alpha": 33245.0,
    "Bravo": 26618.0,
    "Charlie": 22376.0,
    "Delta": 15831.0
  }
}

console.log(`
  ${data['Agent Contribution (Incl Rev)'].Alpha}
  ${data['Agent Contribution (Incl Rev)'].Bravo}
  ${data['Agent Contribution (Incl Rev)'].Charlie}
  ${data['Agent Contribution (Incl Rev)'].Delta}  
`);

但我收到错误消息:类型不匹配。有没有人有想法?

enter image description here

2 个答案:

答案 0 :(得分:2)

您的删除代码行写得不正确。它写着:

ThisWorkbook.Worksheets("Fleet Report").Rows("3:a").EntireRow.Delete

应该说:

ThisWorkbook.Worksheets("Fleet Report").Rows("3:" & a).EntireRow.Delete

另外为了避免行和列号,我个人不喜欢它,你可以将它格式化为:

ThisWorkbook.Worksheets("Fleet Report").Range("A3:A" & a).EntireRow.Delete

希望这有帮助!

答案 1 :(得分:0)

试试这个:

Sub Ticket()
Dim a As Long
Dim WB As Workbook, WS As Worksheet



Set WB = ActiveWorkbook
Set WS = WB.Worksheets("Fleet Report")
Application.Calculation = xlManual
a = WS.Range("A2").End(xlDown).Row


MsgBox "Last Row is " & a