ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   vb-Copy two cells, and paste into another worsksheet (https://www.excelbanter.com/excel-programming/293843-vbulletin-copy-two-cells-paste-into-another-worsksheet.html)

ducmis[_2_]

vb-Copy two cells, and paste into another worsksheet
 
I am having problems writing a macro that copy two cells on the sam
row, and pasting it on another spreadsheet. I want to be able to d
this until there is no more record on the spreadsheet.

Sub copy2cell()
'
' copy2cell Macro
' Macro recorded 4/1/2004 by Duc Tran
'

Range("A1, G1").Select
Selection.Copy
Sheets("Sheet1").Select
Range("A1").Select
ActiveSheet.Paste
activecell.offset(1,-2)

End Sub

this is what i have so far, i need to keep pasting all the records ont
Sheet1. Please help

--
Message posted from http://www.ExcelForum.com


kkknie[_4_]

vb-Copy two cells, and paste into another worsksheet
 
Why not just copy all of column A and paste it to the new sheet. The
do the same with column G. Unless I am misunderstanding...



--
Message posted from http://www.ExcelForum.com


ducmis[_3_]

vb-Copy two cells, and paste into another worsksheet
 
Sub copyesn()
Dim countall As Integer

countall = Range("h1").Value
Range("A1:A(countall)").Select
Selection.Copy
Sheets("Sheet1").Select
ActiveSheet.Paste

End Sub

in this case, cell h1 has a counta function within the spreadsheet t
tell me how many records are there. I did this to know how man
records for my range, but programming like this gives me an error. ho
do i go on about doing this

--
Message posted from http://www.ExcelForum.com


kkknie[_5_]

vb-Copy two cells, and paste into another worsksheet
 
I'd change it to this:


Code
-------------------
Sub copyesn()
Dim countall As Integer

countall = Range("h65536").End(xlUp).Row
Range("A1:A" & countall).Select
Selection.Copy
Sheets("Sheet1").Select
Range("A1").Select
ActiveSheet.Paste

End Su
-------------------

The error was probably in the Range("A1:A(countall)").Select statemen
since you need to concatanate the string. Also, using a counta wil
only work if you have no empty spaces in your column. If you did, i
would not select the entire range. This is why I changed the coutal
definition.



--
Message posted from http://www.ExcelForum.com


ducmis[_5_]

vb-Copy two cells, and paste into another worsksheet
 
K,

Thanks for the great input. My problem was trying to put th
countall--a number--into a string. "A1:A & (countall)" "A1:A(countall)
.. i tried all of these but the correct one. Thanks K. you are th
best

--
Message posted from http://www.ExcelForum.com



All times are GMT +1. The time now is 10:56 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com