Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Selecting ACTIVECELL range in Macro -

I'm trying to create a macro that will move 2 columns of data below
another 2 columns of data. This will then be repeated for a number of
columns so that I get all my data into one just two columns.

There will always be data in each cell, however, the number of rows
that will need to be copied will vary. And this is what is causing my
problems.

I'm recording the Macro with Relative reference turned ON. I believe
this statement is what is what is causing my problem but I'm unsure
how to correct:

ActiveCell.Range("A1:B2").Select

Each time I execute the macro I will want to copy a different number of
rows. I believe this statement is limiting my copy to just 2 rows.

Any suggestions would be appreciated.

Thanks



START DATA
A B C D E F
1 2 3 4 5 6
1 2 3 4 5 6

FINISH DATA
A B C D E F
1 2
1 2
3 4
3 4
5 6
5 6


CURRENT MACRO
Range(Selection, Selection.End(xlDown)).Select
ActiveCell.Range("A1:B2").Select
Selection.Copy
Application.CutCopyMode = False
Selection.Cut
Range("A1").Select
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveSheet.Paste
Range("A1").Select
Selection.End(xlToRight).Select
Selection.End(xlToRight).Select
Range(Selection, Selection.End(xlDown)).Select
ActiveCell.Range("A1:B2").Select
Selection.Copy
Application.CutCopyMode = False
Selection.Cut
Range("A1").Select
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveSheet.Paste
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Selecting ACTIVECELL range in Macro -

Sub Test()
Dim iLastRow As Long
Dim iLastCol As Long
Dim i As Long

iLastRow = Cells(Rows.Count, "A").End(xlUp).Row
iLastCol = Cells(1, Columns.Count).End(xlToLeft).Column
For i = 3 To iLastCol - 1 Step 2
Cells(1, i).Resize(iLastRow, 2).Copy Cells(iLastRow * (i \ 2) + 1,
"A")
Next i
Columns(3).Resize(, iLastCol - 2).Delete

End Sub


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"mar10" wrote in message
ups.com...
I'm trying to create a macro that will move 2 columns of data below
another 2 columns of data. This will then be repeated for a number of
columns so that I get all my data into one just two columns.

There will always be data in each cell, however, the number of rows
that will need to be copied will vary. And this is what is causing my
problems.

I'm recording the Macro with Relative reference turned ON. I believe
this statement is what is what is causing my problem but I'm unsure
how to correct:

ActiveCell.Range("A1:B2").Select

Each time I execute the macro I will want to copy a different number of
rows. I believe this statement is limiting my copy to just 2 rows.

Any suggestions would be appreciated.

Thanks



START DATA
A B C D E F
1 2 3 4 5 6
1 2 3 4 5 6

FINISH DATA
A B C D E F
1 2
1 2
3 4
3 4
5 6
5 6


CURRENT MACRO
Range(Selection, Selection.End(xlDown)).Select
ActiveCell.Range("A1:B2").Select
Selection.Copy
Application.CutCopyMode = False
Selection.Cut
Range("A1").Select
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveSheet.Paste
Range("A1").Select
Selection.End(xlToRight).Select
Selection.End(xlToRight).Select
Range(Selection, Selection.End(xlDown)).Select
ActiveCell.Range("A1:B2").Select
Selection.Copy
Application.CutCopyMode = False
Selection.Cut
Range("A1").Select
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveSheet.Paste
End Sub



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Specifying range relative to activecell in macro KellyInCali Excel Programming 6 November 7th 05 11:42 PM
setting range from activecell in macro Giz Excel Programming 1 March 11th 05 05:16 PM
Trigger macro if an Activecell is within a specific Range helmekki[_44_] Excel Programming 0 October 24th 04 01:36 PM
Trigger macro if an Activecell is within a specific Range helmekki[_43_] Excel Programming 2 October 23rd 04 03:56 PM
selecting a cell relative to activecell in an excel macro Zogann Excel Programming 1 October 17th 03 12:20 PM


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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"