0

I am working with macro that creates email and includes Excel table in a body of an email. My problem is that it does not include last row of the table and cuts it off. Is there anything I can change to avoid last row of the table being omitted?

To define the table range I use following:

Dim count_row, count_col As Integer
Dim Actions as Range

count_row = WorksheetFunction.CountA(Range("B2", Range("B2").End(xlDown)))

count_col = WorksheetFunction.CountA(Range("B2", Range("B2").End(xlToRight)))

Set Actions = Sheets("Name of the sheet"). Range(Cells(2,2), Cells(count_row, count_col))
freeflow
  • 4,129
  • 3
  • 10
  • 18
Mary
  • 25
  • 2
  • [How to find the last used cell](https://stackoverflow.com/questions/11169445/error-in-finding-last-used-cell-in-excel-with-vba). – BigBen Oct 14 '21 at 16:34
  • Also see [this](https://stackoverflow.com/questions/17733541/why-does-range-work-but-not-cells) for why `Sheets("Name of the sheet"). Range(Cells(2,2), Cells(count_row, count_col))` is problematic. – BigBen Oct 14 '21 at 16:34
  • The problem is that you're using the *count* of cells as the row *number*. You're off by one because the range you're counting starts in row 2. – BigBen Oct 14 '21 at 16:36
  • Propably you can use `Set Actions = ActiveWorksheet.Range("B2").CurrentRegion` - if you have a continous rows and columns (s. https://learn.microsoft.com/en-us/office/vba/api/excel.range.currentregion) – Ike Oct 14 '21 at 17:29
  • Thank you all, it is solved now! – Mary Oct 15 '21 at 17:06

0 Answers0