ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Problem with function creation (https://www.excelbanter.com/excel-programming/364564-problem-function-creation.html)

terminator_ba

Problem with function creation
 

Please help me, my question is the following:
How can i create a function in Excel/VBA which copy the value in a cell
that is not the cell in which the function is executed and paste this
value in another cell?

I tried the following:

function transfer(cell1,cell2)
range("cell1").select
selection.copy
range("cell2").select
activesheet.paste
end function

But i got no success, please help me


--
terminator_ba
------------------------------------------------------------------------
terminator_ba's Profile: http://www.excelforum.com/member.php...o&userid=35511
View this thread: http://www.excelforum.com/showthread...hreadid=552826


Paul Lautman

Problem with function creation
 
terminator_ba wrote:
Please help me, my question is the following:
How can i create a function in Excel/VBA which copy the value in a
cell that is not the cell in which the function is executed and paste
this value in another cell?

I tried the following:

function transfer(cell1,cell2)
range("cell1").select
selection.copy
range("cell2").select
activesheet.paste
end function

But i got no success, please help me


The problem with this is that the function would not know when it was
supposed to do this.

If cell1 was A1 and cell2 was B2 then you could just put =A1 in B2

Or you could change the function to a sub like this:

sub transfer(cell1,cell2)
range(cell2).value = range(cell1).value
end sub



terminator_ba[_2_]

Problem with function creation
 

i will try to be clear, i want to copy the value in A1 and paste it in
B1 ONLY if a condition is true. If this condition is true, the value of
A1 is copied into B1 , but if the condition is false, it doesnt happen
anything, the value in B1 is kept. Well I tried to insert the following
function in B1: =If(c1<0;a1) but it returns a False in B1 cell if the
condition is false. I want it to return a value only if the condition
is true, and if the condition is false, it keeps the old value. Its
like a register do you understand?


--
terminator_ba
------------------------------------------------------------------------
terminator_ba's Profile: http://www.excelforum.com/member.php...o&userid=35511
View this thread: http://www.excelforum.com/showthread...hreadid=552826


Paul Lautman

Problem with function creation
 
terminator_ba wrote:
i will try to be clear, i want to copy the value in A1 and paste it in
B1 ONLY if a condition is true. If this condition is true, the value
of A1 is copied into B1 , but if the condition is false, it doesnt
happen anything, the value in B1 is kept. Well I tried to insert the
following function in B1: =If(c1<0;a1) but it returns a False in B1
cell if the condition is false. I want it to return a value only if
the condition is true, and if the condition is false, it keeps the
old value. Its like a register do you understand?


How's about something like:

in B1: =IF(C1<0;A1;'value you want in b1')



Ken McLennan

Problem with function creation
 
G'day there Peepuls,

[This followup was posted to microsoft.public.excel.programming and a
copy was sent to the cited author.]

in B1: =IF(C1<0;A1;'value you want in b1')


I think that should be "=IF(C1<0, A1, 'value you want it b1')".
Commas, not semi-colons. (Paul I think you typed too fast <g)

See ya
Ken McLennan
Qld, Australia

Paul Lautman

Problem with function creation
 
Ken McLennan wrote:
G'day there Peepuls,

[This followup was posted to microsoft.public.excel.programming and a
copy was sent to the cited author.]

in B1: =IF(C1<0;A1;'value you want in b1')


I think that should be "=IF(C1<0, A1, 'value you want it b1')".
Commas, not semi-colons. (Paul I think you typed too fast <g)

See ya
Ken McLennan
Qld, Australia


No, I copied what the OP had used thus:
"...Well I tried to insert the following function in B1: =If(c1<0;a1) but
it returns..."



Ken McLennan

Problem with function creation
 
G'day there Paul,

I think that should be "=IF(C1<0, A1, 'value you want it b1')".
Commas, not semi-colons. (Paul I think you typed too fast <g)


No, I copied what the OP had used thus:
"...Well I tried to insert the following function in B1: =If(c1<0;a1) but
it returns..."


Aha!!! I see. Perhaps I should have checked against the initial
post =).

See ya
Ken


All times are GMT +1. The time now is 05:19 PM.

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