ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Recording a macro (https://www.excelbanter.com/excel-programming/388757-recording-macro.html)

Leslie Isaacs

Recording a macro
 
Hello All

I need a macro that will do the following:

1) increase the selected cell range by including the 3 cells immediately
below the initially-selected cell
2) copy the selected cells (there will be four of them)
3) go to the cell that is 2 cells to the right of the initially-selected
cell
4) paste-transpose

So for e.g. with:
A1 = "Green"
A2 = "Blue"
A3 = "Red"
A4 = "Yellow"

and all other cells empty, if I start the macro with A1 selected, I want it
to result in:

C1 = "Green"
D1 = "Blue"
E1 = "Red"
F1 = "Yellow"

I have tried to do this by recording the macro, but although the
paste-transpose works fine, the cell references are always absolute -
whereas I need to make them relative (i.e. "go down 3 cells" rather than "go
to A4").

What I have so far is:

Range("A1:C4").Select
Selection.Copy
Range("E1").Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone,
SkipBlanks:= _
False, Transpose:=True

Hope someone can help
Many thanks
Les



Jim Rech

Recording a macro
 
When you start recording a macro the Stop Recording toolbar should appear.
The second button on that is Relative Reference. You should click that to
get something much closer to what you want.

--
Jim
"Leslie Isaacs" wrote in message
...
Hello All

I need a macro that will do the following:

1) increase the selected cell range by including the 3 cells immediately
below the initially-selected cell
2) copy the selected cells (there will be four of them)
3) go to the cell that is 2 cells to the right of the initially-selected
cell
4) paste-transpose

So for e.g. with:
A1 = "Green"
A2 = "Blue"
A3 = "Red"
A4 = "Yellow"

and all other cells empty, if I start the macro with A1 selected, I want
it to result in:

C1 = "Green"
D1 = "Blue"
E1 = "Red"
F1 = "Yellow"

I have tried to do this by recording the macro, but although the
paste-transpose works fine, the cell references are always absolute -
whereas I need to make them relative (i.e. "go down 3 cells" rather than
"go to A4").

What I have so far is:

Range("A1:C4").Select
Selection.Copy
Range("E1").Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone,
SkipBlanks:= _
False, Transpose:=True

Hope someone can help
Many thanks
Les




Tom Ogilvy

Recording a macro
 
Sub CopyData()
Selection.Resize(4).Copy
Selection.Offset(0, Selection _
.Columns.Count + 1).Resize(1, 4) _
.PasteSpecial Paste:=xlPasteAll, _
Operation:=xlNone, _
SkipBlanks:=False, _
Transpose:=True
End Sub

worked for me

--
Regards,
Tom Ogilvy

"Leslie Isaacs" wrote:

Hello All

I need a macro that will do the following:

1) increase the selected cell range by including the 3 cells immediately
below the initially-selected cell
2) copy the selected cells (there will be four of them)
3) go to the cell that is 2 cells to the right of the initially-selected
cell
4) paste-transpose

So for e.g. with:
A1 = "Green"
A2 = "Blue"
A3 = "Red"
A4 = "Yellow"

and all other cells empty, if I start the macro with A1 selected, I want it
to result in:

C1 = "Green"
D1 = "Blue"
E1 = "Red"
F1 = "Yellow"

I have tried to do this by recording the macro, but although the
paste-transpose works fine, the cell references are always absolute -
whereas I need to make them relative (i.e. "go down 3 cells" rather than "go
to A4").

What I have so far is:

Range("A1:C4").Select
Selection.Copy
Range("E1").Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone,
SkipBlanks:= _
False, Transpose:=True

Hope someone can help
Many thanks
Les




Leslie Isaacs

Recording a macro
 
Jim and Tom - many thanks indeed - both of your suggestions worked!
Much appreciated.
Les


"Tom Ogilvy" wrote in message
...
Sub CopyData()
Selection.Resize(4).Copy
Selection.Offset(0, Selection _
.Columns.Count + 1).Resize(1, 4) _
.PasteSpecial Paste:=xlPasteAll, _
Operation:=xlNone, _
SkipBlanks:=False, _
Transpose:=True
End Sub

worked for me

--
Regards,
Tom Ogilvy

"Leslie Isaacs" wrote:

Hello All

I need a macro that will do the following:

1) increase the selected cell range by including the 3 cells immediately
below the initially-selected cell
2) copy the selected cells (there will be four of them)
3) go to the cell that is 2 cells to the right of the initially-selected
cell
4) paste-transpose

So for e.g. with:
A1 = "Green"
A2 = "Blue"
A3 = "Red"
A4 = "Yellow"

and all other cells empty, if I start the macro with A1 selected, I want
it
to result in:

C1 = "Green"
D1 = "Blue"
E1 = "Red"
F1 = "Yellow"

I have tried to do this by recording the macro, but although the
paste-transpose works fine, the cell references are always absolute -
whereas I need to make them relative (i.e. "go down 3 cells" rather than
"go
to A4").

What I have so far is:

Range("A1:C4").Select
Selection.Copy
Range("E1").Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone,
SkipBlanks:= _
False, Transpose:=True

Hope someone can help
Many thanks
Les







All times are GMT +1. The time now is 11:00 PM.

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