macro to paste data in alternate cells-pawan

G

Guest

i want to paste data in alternate cells. e.g. i have following 2 columns:
A B
PWV3 DIGOUTHG
ILA3 DIGOUTHG
ILB3 DIGOUTHG
PDE3 DIGOUTHG
ILC3 DIGOUTHG
QWR3 DIGOUTHG
PWV4 DIGOUTHG
ILA4 DIGOUTHG

I want to paste PWV3 in row 1 and 3 of column B. Then I want to paste ILA3
in row 2 and 4 of column B...and so on....it is tedious to do it for large
numner of rows. Can we write macro for this...

thank you...

-Pawan
 
G

Guest

so for ILB3, where would that go? you explanation would indicate 3 and 5 but
that would over-write PWV3.
 
G

Guest

Oh..Pratick....
Unknowingly I wrote in wrong way...
corrected question is here...

i want to paste data in alternate cells. e.g. i have following 2 columns:
 
G

Guest

Sub Main()
DIM Index as Long
DIM rw as Long
index = 1
DO Until Cells(rw,1) = ""
index =index +1
Cells(index,2) = Cells(rw,1)
index = index + 2
Cells(index,2) = Cells(rw,1)

rw=rw+1
LOOP
End Sub
 
G

Guest

I am not able to do this. It is giving run time error : 1004-Applicatio
defined or object defined error. Can u pls help me?
-Pawan
 
D

Dave Peterson

I think Patrick forgot to initialize rw.

Sub Main()
DIM Index as Long
DIM rw as Long
index = 1
rw = 1 '<-- Added
DO Until Cells(rw,1) = ""
index =index +1
Cells(index,2) = Cells(rw,1)
index = index + 2
Cells(index,2) = Cells(rw,1)
rw=rw+1
LOOP
End Sub
 
P

Patrick Molloy

oops !

thanks Dave

Dave Peterson said:
I think Patrick forgot to initialize rw.

Sub Main()
DIM Index as Long
DIM rw as Long
index = 1
rw = 1 '<-- Added
DO Until Cells(rw,1) = ""
index =index +1
Cells(index,2) = Cells(rw,1)
index = index + 2
Cells(index,2) = Cells(rw,1)
rw=rw+1
LOOP
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top