ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Macro to copy current cell (https://www.excelbanter.com/excel-programming/329550-macro-copy-current-cell.html)

[email protected]

Macro to copy current cell
 
Hi,

When I write a macro to copy D1, it always copies D1.

If I move to E1, I would like it to copy E1 (the cell I'm on).

Does anyone know how to present this (cells and rows) as a variable in
a macro?

Thanks a bunch,

Michele


Darrin Henshaw

Macro to copy current cell
 
You could use ActiveCell, rather than a specific cell. That would copy
what cell currently has the focus. Or is there something else you meant
by it?



*** Sent via Developersdex http://www.developersdex.com ***

Ron de Bruin

Macro to copy current cell
 
Hi Michele

Use ActiveCell
ActiveCell.Copy Sheets("Sheet2").range("A1")

Or Selection ?


--
Regards Ron de Bruin
http://www.rondebruin.nl



wrote in message oups.com...
Hi,

When I write a macro to copy D1, it always copies D1.

If I move to E1, I would like it to copy E1 (the cell I'm on).

Does anyone know how to present this (cells and rows) as a variable in
a macro?

Thanks a bunch,

Michele




[email protected]

Macro to copy current cell
 
I tried your suggestion to use Active Cell, but now I get an error on
ActiveSheet.Paste. I'm basically, coping cell contents from one
spreadsheet to another based on the row I'm in. Here's a few of the
lines.

Workbooks.Open Filename:= _
"C:\Documents and Settings\Administrator\My
Documents\CustomSafety\010184641.xls"
Range("A11:B11").Select
Windows("Cust.xls").Activate
ActiveCell.Copy Sheets("CustomerList").Range("A1")
Windows("010184641.xls").Activate
ActiveSheet.Paste
Range("C11").Select
Windows("Cust.xls").Activate
Range("B6").Select
Application.CutCopyMode = False
Selection.Copy
Windows("010184641.xls").Activate
ActiveSheet.Paste

Thanks for replying.

Michele


Ron de Bruin

Macro to copy current cell
 
Hi

The example line I posted will copy the activecell in sheet2 cell A1
ActiveCell.Copy Sheets("Sheet2").Range("A1")

There is nothing on the clipboard now that's why you get the error
Tell us exactly what you want to do and we can change the macro for you



--
Regards Ron de Bruin
http://www.rondebruin.nl



wrote in message oups.com...
I tried your suggestion to use Active Cell, but now I get an error on
ActiveSheet.Paste. I'm basically, coping cell contents from one
spreadsheet to another based on the row I'm in. Here's a few of the
lines.

Workbooks.Open Filename:= _
"C:\Documents and Settings\Administrator\My
Documents\CustomSafety\010184641.xls"
Range("A11:B11").Select
Windows("Cust.xls").Activate
ActiveCell.Copy Sheets("CustomerList").Range("A1")
Windows("010184641.xls").Activate
ActiveSheet.Paste
Range("C11").Select
Windows("Cust.xls").Activate
Range("B6").Select
Application.CutCopyMode = False
Selection.Copy
Windows("010184641.xls").Activate
ActiveSheet.Paste

Thanks for replying.

Michele





All times are GMT +1. The time now is 07:08 PM.

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