Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Is there any other way to shorter it?


  • Please log in to reply
14 replies to this topic
Xia Mey
  • Members
  • 105 posts
  • Last active: Oct 01 2015 01:55 PM
  • Joined: 23 Dec 2012

dear all. this code copy cell step by step. do you know any other way to write the code easier?

if I want to copy until A1000 then B1000. Do I have to write like this to A1000 then B1000?

Xl.Range("A1").Copy
Xl.Range("A2").Copy
Xl.Range("A3").Copy
Xl.Range("A4").Copy
Xl.Range("A5").Copy
Xl.Range("A6").Copy
Xl.Range("A7").Copy
Xl.Range("A8").Copy
Xl.Range("A9").Copy
Xl.Range("A10").Copy
Xl.Range("B1").Copy
Xl.Range("B2").Copy
Xl.Range("B3").Copy
Xl.Range("B4").Copy
Xl.Range("B5").Copy
Xl.Range("B6").Copy
Xl.Range("B7").Copy
Xl.Range("B8").Copy
Xl.Range("B9").Copy
Xl.Range("B10").Copy

Thank you



None
  • Members
  • 3199 posts
  • Last active: Nov 05 2015 09:55 PM
  • Joined: 28 Nov 2009

oops thought you wanted to copy all at once

Range("A1:A1000").Copy 

 

 

I think this is what you need

 For Each c In Worksheets("Sheet1").Range("A1:A1000").Cells
   c.Copy
 Next

 

 


Xia Mey
  • Members
  • 105 posts
  • Last active: Oct 01 2015 01:55 PM
  • Joined: 23 Dec 2012

error on line... For Each c In Worksheets("Sheet1").Range("A1:A1000").Cells



None
  • Members
  • 3199 posts
  • Last active: Nov 05 2015 09:55 PM
  • Joined: 28 Nov 2009

The code is for macros in excel



Xia Mey
  • Members
  • 105 posts
  • Last active: Oct 01 2015 01:55 PM
  • Joined: 23 Dec 2012

onh..

 

how to make the code to ahk script?

 

and one more question. clipboard is where we save text when we copy right?

 

how to paste back the text? and how to start the clipboard?

 

clipboard = my text. like this?



tidbit
  • Administrators
  • 2709 posts
  • Hates playing Janitor
  • Last active: Jan 15 2016 11:37 PM
  • Joined: 09 Mar 2008

Perhaps: 

 

copied := Xl.Range("A1:B10").Copy
msgbox %copied%

rawr. be very afraid
*poke*
. Populate the AutoHotkey city. Pointless but somewhat fun. .


HotKeyIt
  • Moderators
  • 7439 posts
  • Last active: Jun 22 2016 09:14 PM
  • Joined: 18 Jun 2008
xl:=ComObjActive("Excel.Application")
For c In xl.Worksheets("Tabelle1").Range("A1:A1000").Cells
{
  Clipboard:=""
  c.Copy
  ClipWait,0.5
  MsgBox % Clipboard
}


Xia Mey
  • Members
  • 105 posts
  • Last active: Oct 01 2015 01:55 PM
  • Joined: 23 Dec 2012

error code



Xia Mey
  • Members
  • 105 posts
  • Last active: Oct 01 2015 01:55 PM
  • Joined: 23 Dec 2012

Perhaps: 

 

copied := Xl.Range("A1:B10").Copy
msgbox %copied%

not like that. Thank anyway



Xia Mey
  • Members
  • 105 posts
  • Last active: Oct 01 2015 01:55 PM
  • Joined: 23 Dec 2012
xl:=ComObjActive("Excel.Application") For c In xl.Worksheets("Tabelle1").Range("A1:A1000").Cells { Clipboard:="" c.Copy ClipWait,0.5 MsgBox % Clipboard }

 

code error



Guest10
  • Members
  • 1216 posts
  • Last active: Oct 30 2015 05:12 PM
  • Joined: 27 Oct 2012
dear all. this code copy cell step by step. do you know any other way to write the code easier?

if I want to copy until A1000 then B1000. Do I have to write like this to A1000 then B1000?

Xl.Range("A1").Copy
Xl.Range("A2").Copy
Xl.Range("A3").Copy
Xl.Range("A4").Copy
Xl.Range("A5").Copy
Xl.Range("A6").Copy
Xl.Range("A7").Copy
Xl.Range("A8").Copy
Xl.Range("A9").Copy
Xl.Range("A10").Copy
Xl.Range("B1").Copy
Xl.Range("B2").Copy
Xl.Range("B3").Copy
Xl.Range("B4").Copy
Xl.Range("B5").Copy
Xl.Range("B6").Copy
Xl.Range("B7").Copy
Xl.Range("B8").Copy
Xl.Range("B9").Copy
Xl.Range("B10").Copy

Thank you

This is how to copy 1000 cells (A, B, C):

Sub Copy_Cells()
'
' Copy_Cells Macro
'
Dim i As Integer

Application.ScreenUpdating = False

For i = 1 To 1000

strRange1 = "A" & (i)
strRange2 = "B" & (i)
strRange3 = "C" & (i)

Windows("MyWorksheet").Activate
Sheets("Sheet1").Select

Range(strRange1).Select
Selection.Copy
Range(strRange2).Select
Selection.Copy
Range(strRange3).Select
Selection.Copy

Next i

Application.ScreenUpdating = True

End Sub


Xia Mey
  • Members
  • 105 posts
  • Last active: Oct 01 2015 01:55 PM
  • Joined: 23 Dec 2012

This is how to copy 1000 cells (A, B, C):

Sub Copy_Cells()
'
' Copy_Cells Macro
'
Dim i As Integer

Application.ScreenUpdating = False

For i = 1 To 1000

strRange1 = "A" & (i)
strRange2 = "B" & (i)
strRange3 = "C" & (i)

Windows("MyWorksheet").Activate
Sheets("Sheet1").Select

Range(strRange1).Select
Selection.Copy
Range(strRange2).Select
Selection.Copy
Range(strRange3).Select
Selection.Copy

Next i

Application.ScreenUpdating = True

End Sub

The code is for excel or ahk?



hafizimran
  • Members
  • 6 posts
  • Last active: Jan 02 2013 03:37 PM
  • Joined: 21 Dec 2012

Where do you want to retrieve the copied data (in msgbox, variable or some other)?

 

you may copy all the cells in range as:

xl.Range("A1:B1000").Copy


Xia Mey
  • Members
  • 105 posts
  • Last active: Oct 01 2015 01:55 PM
  • Joined: 23 Dec 2012

I got the code. but I dont know how to make it paste to where I want beside excel.

here is my code

 

FileSelectFile, Path
Xl := ComObjCreate("Excel.Application")
Xl.Workbooks.Open(Path) ;open an existing file
Xl.Visible := True

^+f::
Clipboard = %clipboard%
{
Xl.Range("A1").Copy
send, %clipboard%
send, {tab}{tab}{tab}
Xl.Range("D1").Copy
send, %clipboard%
send, {tab}
Xl.Range("A2").Copy
send, %clipboard%
send, {tab}{tab}
Xl.Range("C1").Copy
send, %clipboard%
send, {tab}
Xl.Range("D2").Copy
send, %clipboard%
send, {tab}
Xl.CutCopyMode := False
}

And I don't know why It paste from top to bottom. even though I tried put some {tab} but no use

 

please help me out. many thank



Xia Mey
  • Members
  • 105 posts
  • Last active: Oct 01 2015 01:55 PM
  • Joined: 23 Dec 2012

Thank you all of you. It is solved.