Re: Excel- copy and pasting
coolcatch:
========
Ahh, grasshopper, you've discovered that you can not reference cells programatically with recorded Macros!
This may get you at least started:
Code:
Option Explicit
Sub Iter_Test()
Dim irow As Integer 'Row Counter
Dim icol As Integer 'Column Counter
Dim arange As Range 'A Range Object Variable
icol = 2 'Initialize the Column Counter
'Iterate down the column showing the cell addresses and contents
For irow = 1 To 10
MsgBox (Cells(irow, icol).Address & " | " & Cells(irow, icol).Value)
Next irow
'Adjust irow back to the last iterated row number
irow = irow - 1
'Here is a sample of setting a range of cells programatically
Set arange = Range(Cells(1, icol), Cells(irow, icol))
MsgBox (arange.address)
End Sub
It is a primitive example of iterating through cells programatically, and referencing a range of cells.
Good luck in your efforts.
Re: Excel- copy and pasting
could u just talk me through how exactly i would get that (what you have written) to help me do what i want to do, i understand the vairables u defined but then what do i do about the actual copying and pasting of the cells in excel, where do i implement that, and how exactly do i define a range of cells, say from 1 to 2000 in the row?
Re: Excel- copy and pasting
hi coolcatch
if u use vb macro wizard to record copy paste, then what u would get is like below
VB Code:
Sub Macro1()
'
' Macro1 Macro
' Macro recorded 25/05/2005 by USER
'
'
Range("C10").Select
Selection.Copy
Sheets("Sheet2").Select
Range("C8").Select
ActiveSheet.Paste
End Sub
which is kinda long, but if u code urself, what u might have is probably like below
VB Code:
Sub mycopy()
Sheet1.Range("C10").Copy
Sheet2.Range("C20").PasteSpecial xlPasteValues
End Sub
i hope this could help you
1 Attachment(s)
Re: Excel- copy and pasting
thanks asmdev but my problem is not the copying and pasting, its trying to get the thing to copy and paste about 2000 cells in one row, down in a vertical column in my groups of seven, i really dont wanna do that by hand, so id prefer to have it just so that it keeps moving the entire row down to the left and taking the 7 cells next to my first set of cells and pasting them below in the a column, and then the next seven below that, and the next seven below that, see my picture if u dont understand
Re: Excel- copy and pasting
Re: Excel- copy and pasting
VB Code:
f = 7 'no of entries per listing +1
Range("a1").Activate
Selection.End(xlToRight).Select
lcell = ActiveCell.Column
crow = ActiveCell.Row
Do
Range(Cells(crow, f + 1), Cells(crow, lcell)).Select
crow = crow + 1: lcell = lcell - f
Selection.Cut Destination:=Range(Cells(crow, 1), Cells(crow, lcell))
Loop While lcell > f
this seems to work, but you might have to allow for a header row
pete