Problem with function creation

  • Thread starter Thread starter terminator_ba
  • Start date Start date
T

terminator_ba

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 said:
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
 
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 said:
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')
 
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
 
Ken said:
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..."
 
G'day there Paul,
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
 
Back
Top