Copying Excel range to another sheet

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
rspai
Posts: 9
Joined: 15 Oct 2019, 03:38

Copying Excel range to another sheet

Post by rspai » 17 Oct 2021, 06:35

Code: Select all

Xl := ComObjActive("Excel.Application")
filename:= "D:\Selenium_Excel\FI_Data.xlsx"
wbk:=XL.Workbooks.Open(filename)
dws2:=wbk.sheets("BMData")
tws:=wbk.Sheets("tempData")
xlDown := -4121
xlUp := -4162
tws.Select
copyrange:= tws.Range("B1", tws.Range("B1").End(xlDown))
dws2.Range("a1"):= copyrange.value
wbk.Save()
A workbook has two sheets "BMData" and "tempData". Tempdata has values in Column B but the count of rows changes. Hence, I have used the End(xlDown) code above. However, in the destination sheet (dws2/"BMData") only the value in B1 is copied to a1 (ie only one value is copied. Currently column B in tempData sheet has 13 values in 13 rows).

User avatar
flyingDman
Posts: 2817
Joined: 29 Sep 2013, 19:01

Re: Copying Excel range to another sheet

Post by flyingDman » 17 Oct 2021, 10:44

try:

Code: Select all

Xl := ComObjActive("Excel.Application")
sht1:=xl.sheets("sheet1")
sht2:=xl.sheets("sheet2")
lstrw := sht2.range("B1").End(-4121).row
sht1.Range("A1:A" lstrw) := sht2.Range("B1:B" lstrw).value
or (using the clipboard)

Code: Select all

Xl := ComObjActive("Excel.Application")
sht1:=xl.sheets("sheet1")
sht2:=xl.sheets("sheet2")
lstrw := sht2.range("B1").End(-4121).row
sht2.Range("B1:B" lstrw).Copy(sht1.Range("A1"))
14.3 & 1.3.7

Post Reply

Return to “Ask for Help (v1)”