EXCEL macro that will vary when copied

G

Guest

I want a "macro button" that acts on one row to be able to be copied in many
other rows(1200), without having to write a new macro for each row. (to
Copy-Paste it and have it act the same as an EXCEL formula, changing the
relative addresses automatically).
In paricular, all the button does is take the cursor "Home" in the same row
(leftmost column), insert the digit "1" in that cell and move one column to
the right.
Any ideas? (I don't speak "Basic"....)
 
G

Guest

Michael

The following will do what you want

Sub t()
Dim r As Long
r = ActiveCell.Row
Cells(r, 1) = 1
Cells(r, 2).Select
End Sub

Copy this into a VB module (ALt + F11) select Insert, Module and paste the
macro into the module.

Press Ctrl + Q to return to the sheet.

I would not use a macro button to execute the macro unless you have Freezed
the panes. Instead assign a shortcut key. While in Excel choose Tools, Macros
(Alt + F8), click once on the macro to select it if necessary and click the
Options Button.

Assign the Letter Q, it does not seem to be used for anything and click ok.
Press Ctrl + Q to run the code.

Peter
 

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