macro code question

M

Maria

Hi guys,

I know this is a MAC forum and I am on excel 2003 but I thought maybe
someone can help...

I have a button that when you click on it, it makes cell A1 duplicate what
is in cell A2. But I need to have clicked on A1 before I press the button
for it to work. For example if I happen to be on cell D4 and click the
button, then a 0 goes in the D4 cell and nothing happens in the A1, it does
not not duplicate whats in A2.

I would like the D4 cell to be ignored and just have the button coded to
where when I click it, regardless of where my cursor is, the A1 cell will
duplicate what is in A2.

I hope it is a simple line or command that I can put in the code. Thanks to
anyone who can help! -maria

Here is the code I have for the button now:

Private Sub CommandButton1_Click()
ActiveCell.FormulaR1C1 = ""
ActiveCell.FormulaR1C1 = "=R[1]C"
ActiveCell.Offset(1, 0).Range("A1").Select
End Sub
 
B

Bernd P

Hello Maria,

Private Sub CommandButton1_Click()
Range("A1").Formula = Range("A2").value
End Sub

Regards,
Bernd
 
M

Maria

Hi Bernd again,

I was quick to say thanks before I have one more question for you...

Let's say I wanted A1 to copy what is in A2 of Sheet 2 in the same workbook,
how would I do that?

I tried sheet2!A2 but that did not seem to work.

Thanks again for you help, your great!
-Maria
 
J

Jarek Kujawa

how about:

Sheets("sheet2").Range("A2").Copy
Sheets("sheet1").Range("A1").PasteSpecial Paste:=xlPasteValues
 
B

Bernd P

Hello Maria,

Private Sub CommandButton1_Click()
Sheets("Sheet1").Range("A1").Formula = Sheets("Sheet2")Range
("A2").value
End Sub

Regards,
Bernd
 
C

CurlyDave

Hi guys,

I know this is a MAC forum and I am on excel 2003 but I thought maybe
someone can help...

I have a button that when you click on it, it makes cell A1 duplicate what
is in cell A2.  But I need to have clicked on A1 before I press the button
for it to work.  For example if I happen to be on cell D4 and click the
button, then a 0 goes in the D4 cell and nothing happens in the A1, it does
not not duplicate whats in A2.  

I would like the D4 cell to be ignored and just have the button coded to
where when I click it, regardless of where my cursor is, the A1 cell will
duplicate what is in A2.

I hope it is a simple line or command that I can put in the code.  Thanks to
anyone who can help!  -maria

Here is the code I have for the button now:

Private Sub CommandButton1_Click()
 ActiveCell.FormulaR1C1 = ""
    ActiveCell.FormulaR1C1 = "=R[1]C"
    ActiveCell.Offset(1, 0).Range("A1").Select
End Sub
worksheets("Sheet1").range("A1")=worksheets(Sheet2").range("A2").value
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top