0

Hi All a piece of my code below throws an error if there I only one row found as out put. If it is working on more than one row it works fine though.

I have only included the naughty section of the macro

MyCode:

Dim LZ As Long

LZ = ActiveSheet.UsedRange.Find("*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
Range("AM2").AutoFill Destination:=Range("AM2:AM" & LZ)
Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73
  • `if ActiveSheet.UsedRange.rows.count=2 then lz=2 else...` why not use `usedrange.rows.count`? – Nathan_Sav Feb 19 '19 at 11:15
  • And please, avoid using ActiveSheet (and Select too). It's prone to error. https://www.thespreadsheetguru.com/blog/vba-guide-to-referencing-excel-worksheet-tabs – Tim Stack Feb 19 '19 at 11:18
  • You have to be careful when using `.Find` to find the last row. You may want to see [This](https://stackoverflow.com/questions/11169445/error-in-finding-last-used-cell-in-vba/11169920#11169920) – Siddharth Rout Feb 19 '19 at 11:19
  • @TimStack: No need to go that faaar... Checkout something from [stackoverflow](https://stackoverflow.com/questions/10714251/how-to-avoid-using-select-in-excel-vba) ;) – Siddharth Rout Feb 19 '19 at 11:20
  • Nothing wrong with some external sources – Tim Stack Feb 19 '19 at 11:40

0 Answers0