ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Variable Cell Value within a macro (https://www.excelbanter.com/excel-discussion-misc-queries/125277-variable-cell-value-within-macro.html)

Ron (Bismark)

Variable Cell Value within a macro
 
I have a limited ability with macros. I record them rather than write them.

What I'm trying to do is write a macro that will copy a cell value and paste
it to another sheet. Sounds simple. But the location it needs to be pasted is
a variable row with a fixed column.

I have a cell on sheet 1 (F7) which details the cell to go to in sheet 2
(R?C33) (?= variable row).

Can anyone advise.

Many thanks.

Dave Peterson

Variable Cell Value within a macro
 
Option Explicit
sub testme()
dim DestCell as range
dim OrigCell as range

set origcell = worksheets("sheet1").range("f7")

with worksheets("sheet2")
set destcell = .cells(.rows.count,33).end(xlup).offset(1,0)
end with

origcell.copy _
destination:=destcell

'or
destcell.value = origcell.value
end sub

I used the next available row in column 33.

Ron (Bismark) wrote:

I have a limited ability with macros. I record them rather than write them.

What I'm trying to do is write a macro that will copy a cell value and paste
it to another sheet. Sounds simple. But the location it needs to be pasted is
a variable row with a fixed column.

I have a cell on sheet 1 (F7) which details the cell to go to in sheet 2
(R?C33) (?= variable row).

Can anyone advise.

Many thanks.


--

Dave Peterson


All times are GMT +1. The time now is 03:41 AM.

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