Paste this as new action (tab) in Excel VBO:
https://pastebin.com/x0gg5dK9Doesn't need anything to be selected etc, just give it an instance, workbook, worksheet, source range, optionally destination (uses CurrentRegion when blank), optionally xlAutoFillType
Edit to clarify: Not using original code, my own solution.
My point is that you don't need to activate anything, this should work just fine:
wb = GetWorkbook(Handle, Workbook)
ws = GetWorksheet(Handle, Workbook, Worksheet)
ws.Range(SourceRange).AutoFill(Destination:=ws.Range(FillRange))
My version has extra options:
- worksheet index instead of name (optional, either will do)
- ActiveSheet is used, when worksheet name and index are not set.
- blank dstRange, then it tries to guess it with CurrentRegion, which is not exactly what Excel does internally, but close and good enough for most cases
- xlAutoFillType, because sometimes xlFillDefault is not what you want.
------------------------------
Andrey Kudinov
Project Manager
MobileTelesystems PJSC
Europe/Moscow
------------------------------