Please check my code & tell me where i'm doing it wrong. Cant make it work. Small code. Thanks

pedie

Well-known Member
Joined
Apr 28, 2010
Messages
3,875
I dont know why my code does not leave a row before pasting....
please check where is it wrong.
Thanks ped;)

Code:
sub try1()
Selection.Copy
          Sheets("Data").Select
          Range("b2").Select
          Do Until ActiveCell.Value = ""
          ' i have place (1,0) to leave 1 row before pasting...
          ActiveCell.Offset(1, 0).Select
          Loop
activesheet.paste
end sub
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
just add one more line:
Code:
Sub try1()
Selection.Copy
          Sheets("Data").Select
          Range("b2").Select
          Do Until ActiveCell.Value = ""
          ' i have place (1,0) to leave 1 row before pasting...
          ActiveCell.Offset(1, 0).Select
          Loop
[COLOR=Red]ActiveCell.Offset(1, 0).Select[/COLOR]
ActiveSheet.Paste
End Sub
 
Upvote 0
It does not work. I don't know why.

It leaves 1 row before pasting that is 1 row below b2. then when i run the code again does the same and overide preious data.
I want to find next empty one, then leave one skip 1 row and paste.:biggrin:
 
Upvote 0
What are you trying to do?? Your code makes no sense.
All you need is one line
Code:
Selection.Copy Range("B"&Cells(Rows.Count,"B").End(xlUp).Row +1 )

lenze
 
Upvote 0
Hello

try.

<font face=Courier New><SPAN style="color:#00007F">Sub</SPAN> try1()<br>Selection.Copy<br>          Sheets("Data").Select<br>          Range("b2").Select<br>          <SPAN style="color:#00007F">Do</SPAN> <SPAN style="color:#00007F">Until</SPAN> ActiveCell.Value = ""<br>          <SPAN style="color:#007F00">' i have place (1,0) to leave 1 row before pasting...</SPAN><br>          ActiveCell.Offset(2, 0).Select<br>          <SPAN style="color:#00007F">Loop</SPAN><br>ActiveSheet.Paste<br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br></FONT>
 
Upvote 0
pedie

You really should avoid using Selection/Select/ActiveCell etc.

Not only are they not usually needed but they can actually cause problems.

One other thing you could try is posting an explanation, in words, what the code is meant to do.:)

Obviously you are copying/pasting but it's not clear exactly what you are copying/pasting or where you are doing it.
 
Upvote 0
Lenze, i hope you know that i have to copy and paste it in data sheet from sheet1.

Sorry for confusion.:biggrin:
 
Upvote 0
Meldoc, Lenze, Norie...

I am still having trouble making it work...it does not leave any row..
maybe you can please redesign the whole code.:biggrin:

Thanks for helping

Current code.
Code:
Sub try1()
Sheets("Sheet1").Select
          Range("B2").Select
          Selection.CurrentRegion.Select
          Selection.Copy
          Sheets("Data").Select
          Range("b2").Select
          Do Until ActiveCell.Value = ""
          ' i have place (1,0) to leave 1 row before pasting...
          ActiveCell.Offset(2, 0).Select
          Loop
Selection.PasteSpecial Paste:=xlPasteAllUsingSourceTheme, Operation:=xlNone _
        , SkipBlanks:=False, Transpose:=False
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,640
Messages
6,125,976
Members
449,276
Latest member
surendra75

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top