Home |
Search |
Today's Posts |
#1
|
|||
|
|||
Perform oiperations relative to initial selected cell
I guess I did a pretty bad job of describing my question. I truly appreciate
your reply but it didn't do what I needed. Let me ask it this way, I am pasting a copy of a simple macro below. Sub Macro3() ' ' Macro3 Macro ' Macro recorded 5/30/05 by new ' ' Keyboard Shortcut: Ctrl+z ' Range("G2:G4").Select Selection.Copy Range("H1:J1").Select Selection.PasteSpecial Paste:=xlAll, Operation:=xlNone, SkipBlanks:=False _ , Transpose:=True Range("G7").Select End Sub The problem I have is that is copies and pastes the same data over and over no matter what cell I have selected when I run the macro. What I need is for the macro to run from the cell I have selected at the time I run the macro and to perform the copy and paste operations relative to the cell that is selected when the macro is ran. To ask it another way, when I run the macro for the FIRST time cell G2 is selected when the macro begins execution. At the completion of the macro G7 is left selected. When I run the macro a second time (initiating it with G7 selected) I need it to select range G7:G9, copy it, then select H2:J2 and past the data transposed to those cells. I converting column data to row data. I just need the macro to excute on cells relative to the initial cell I have selected when I run it, and NOT use absolute cell values. If it uses absolute values then I am always writing into H1:J1. Not what I want. Can you help? Thanks Still sctatching my head. |
#2
|
|||
|
|||
try
sub try() r=activecell.row c=activecell.column if r = 2 the tgr = 1 else tgr=(r-1)/6 for t=1 to 4 cells(tgr,c+t)=cells(r+t-1,c) next t end sub Select the top cell of interest and run the macro. If it works how you want it to work, I would make it more formal by using the option explicit staement and "Dim"S for all of the variables "scratching my head" wrote: I guess I did a pretty bad job of describing my question. I truly appreciate your reply but it didn't do what I needed. Let me ask it this way, I am pasting a copy of a simple macro below. Sub Macro3() ' ' Macro3 Macro ' Macro recorded 5/30/05 by new ' ' Keyboard Shortcut: Ctrl+z ' Range("G2:G4").Select Selection.Copy Range("H1:J1").Select Selection.PasteSpecial Paste:=xlAll, Operation:=xlNone, SkipBlanks:=False _ , Transpose:=True Range("G7").Select End Sub The problem I have is that is copies and pastes the same data over and over no matter what cell I have selected when I run the macro. What I need is for the macro to run from the cell I have selected at the time I run the macro and to perform the copy and paste operations relative to the cell that is selected when the macro is ran. To ask it another way, when I run the macro for the FIRST time cell G2 is selected when the macro begins execution. At the completion of the macro G7 is left selected. When I run the macro a second time (initiating it with G7 selected) I need it to select range G7:G9, copy it, then select H2:J2 and past the data transposed to those cells. I converting column data to row data. I just need the macro to excute on cells relative to the initial cell I have selected when I run it, and NOT use absolute cell values. If it uses absolute values then I am always writing into H1:J1. Not what I want. Can you help? Thanks Still sctatching my head. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|