ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Relative navigation in macro (https://www.excelbanter.com/excel-programming/408730-relative-navigation-macro.html)

Steve Vincent

Relative navigation in macro
 
I have a macro that I need to (1) insert a line, (2) copy/paste values only,
(3) copy/paste normal (contents of cell), and (4) delete a line. This
currently works only in the cell(s) where I created the macro. How can I
modify the macro so that it will execute anywhere (in different sheets, that
is) ? Here is the code:

Sub copypaste()
'
' copypaste Macro
'

'
Rows("526:526").Select
Selection.Insert Shift:=xlDown
Rows("525:525").Select
Selection.Copy
Rows("526:526").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Range("F527:H527").Select
Application.CutCopyMode = False
Selection.Copy
Range("F525").Select
ActiveSheet.Paste
Rows("527:527").Select
Application.CutCopyMode = False
Selection.Delete Shift:=xlUp
End Sub




Jim Thomlinson

Relative navigation in macro
 
The code you have posted will operate on the active sheet. Did you want it to
operate relative to the active cell so that you could pick a row and perform
the operations relative to that row???
--
HTH...

Jim Thomlinson


"Steve Vincent" wrote:

I have a macro that I need to (1) insert a line, (2) copy/paste values only,
(3) copy/paste normal (contents of cell), and (4) delete a line. This
currently works only in the cell(s) where I created the macro. How can I
modify the macro so that it will execute anywhere (in different sheets, that
is) ? Here is the code:

Sub copypaste()
'
' copypaste Macro
'

'
Rows("526:526").Select
Selection.Insert Shift:=xlDown
Rows("525:525").Select
Selection.Copy
Rows("526:526").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Range("F527:H527").Select
Application.CutCopyMode = False
Selection.Copy
Range("F525").Select
ActiveSheet.Paste
Rows("527:527").Select
Application.CutCopyMode = False
Selection.Delete Shift:=xlUp
End Sub




Steve Vincent

Relative navigation in macro
 
Jim,

Yes, I would like this to operate relative to the active cell. Sorry I
didn't clarify!



"Jim Thomlinson" wrote:

The code you have posted will operate on the active sheet. Did you want it to
operate relative to the active cell so that you could pick a row and perform
the operations relative to that row???
--
HTH...

Jim Thomlinson


"Steve Vincent" wrote:

I have a macro that I need to (1) insert a line, (2) copy/paste values only,
(3) copy/paste normal (contents of cell), and (4) delete a line. This
currently works only in the cell(s) where I created the macro. How can I
modify the macro so that it will execute anywhere (in different sheets, that
is) ? Here is the code:

Sub copypaste()
'
' copypaste Macro
'

'
Rows("526:526").Select
Selection.Insert Shift:=xlDown
Rows("525:525").Select
Selection.Copy
Rows("526:526").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Range("F527:H527").Select
Application.CutCopyMode = False
Selection.Copy
Range("F525").Select
ActiveSheet.Paste
Rows("527:527").Select
Application.CutCopyMode = False
Selection.Delete Shift:=xlUp
End Sub





All times are GMT +1. The time now is 09:04 PM.

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