How to macro to relative position

J

jk9533

Sheet2.Select
Range("A2").Select
Selection.Copy
Sheet1.Select
Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Sheets("Input Sheet").Select
Range("B2").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Input View").Select
Range("C1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
End Sub

How to I get the range select to be relative?
 
J

jk9533

Range("A2").Select
I linked this macro to a button on the same row. So if they push the button
on row 2 it should read A2. If they push the button on row3 then A3 and so
on and so on.

Any help you can provide is greatly appreciated.
 
J

JE McGimpsey

One way:

With ActiveCell
If .Parent.Name = "Input Sheet" Then
Sheet1.Range("A1").Value = .Parent.Cells(.Row, 1).Value
Sheet1.Range("C1").Value = .Parent.Cells(.Row, 2).Value
End If
End With

(Assuming Sheet2 = "Input Sheet" and Sheet1 = "Input View")
 
J

jk9533

Not quite.

I need the macro to copy and paste A(X) from Sheet1 to $A$1 of Sheet2 based
on the row position of A(X).

So if I click the button on row 1 on sheet 1 then it will pasts the value of
A1 sheet1 on Sheet2 $A$1. If I click the button on row2 on sheet 1 then it
will paste the value of A2 sheet1 on Sheet2 $A$1

Any suggestions
 
J

JE McGimpsey

Hmm... that's the opposite of your recorded macro, but the change is
simple:

With ActiveCell
If .Parent.Name = Sheet1.Name Then
Sheet2.Range("A1").Value = .Parent.Cells(.Row, 1).Value
Sheet2.Range("C1").Value = .Parent.Cells(.Row, 2).Value
End If
End With


This assumes that by "click the button on row2" you mean, "click the
button with a cell on row 2 active". If you actually have different
buttons, then the answer will depend on what kind of button (i.e., Forms
toolbar or Controls Toolbox).
 
J

jk9533

Thanks it works

JE McGimpsey said:
Hmm... that's the opposite of your recorded macro, but the change is
simple:

With ActiveCell
If .Parent.Name = Sheet1.Name Then
Sheet2.Range("A1").Value = .Parent.Cells(.Row, 1).Value
Sheet2.Range("C1").Value = .Parent.Cells(.Row, 2).Value
End If
End With


This assumes that by "click the button on row2" you mean, "click the
button with a cell on row 2 active". If you actually have different
buttons, then the answer will depend on what kind of button (i.e., Forms
toolbar or Controls Toolbox).
 

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