Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel Macro - Help 1

Status
Not open for further replies.

NSGuard

MIS
Jul 15, 2004
29
US
I'm looking to make a macro that takes data in column A and seperate it into three columns. I'm able to do it by setting up the macro manually, but is there a way to loop it to do it automatically as long as there is information in column A?

-------------------------------------------------------

This is what I've got:

A B C
1
2
3
1
2
3
1
2
3

This is what I want it to do:

A B C
1 2 3
1 2 3
1 2 3

-------------------------------------------------------


I've got code from a macro, but I only did two lines as an example and I was wondering if anyone knew how to code it to run through the entire column or until this isn't any data left in column A.

Thanks for any help in advance.



This is the macro code that I have for just running the 2 columns.

ActiveCell.Offset(1, 0).Range("A1").Select
Selection.Cut Destination:=ActiveCell.Offset(-1, 1).Range("A1")
ActiveCell.Offset(1, 0).Range("A1").Select
Selection.Cut Destination:=ActiveCell.Offset(-2, 2).Range("A1")
ActiveCell.Offset(1, 0).Range("A1").Select
Selection.Cut Destination:=ActiveCell.Offset(-2, 0).Range("A1")
ActiveCell.Offset(1, 0).Range("A1").Select
Selection.Cut Destination:=ActiveCell.Offset(-3, 1).Range("A1")
ActiveCell.Offset(1, 0).Range("A1").Select
Selection.Cut Destination:=ActiveCell.Offset(-4, 2).Range("A1")
ActiveCell.Offset(-4, 2).Range("A1").Select
 
An almost identical question was asked yesterday in thread68-1280183.

I suggested the following code:
Code:
Sub InsertAnyNameYouWantHere()
'   Loops through cells in column B ajacent to populated cells in column A
For Each Cell In Range("B1:B" & ActiveSheet.UsedRange.Rows.Count)
    '   sets the value in column B equal to the cell 1 row down, 1 row left
    Cell.Value = Cell.Offset(1, -1).Value
    '   sets the value in column C equal to the cell 2 rows down, 2 rows left
    Cell.Offset(, 1).Value = Cell.Offset(2, -1).Value
    '   Deletes the 2 rows below the one being manipulated
    Range(Cell.Offset(1), Cell.Offset(2)).EntireRow.Delete
Next Cell

For future reference, VBA-specific questions should be asked in forum707, the VBA Visual Basic for Applications (Microsoft) Forum

[tt]_____
[blue]-John[/blue][/tt]
[tab][red]The plural of anecdote is not data[/red]

Help us help you. Please read FAQ181-2886 before posting.
 
Appreciate the help. I was able to manipulate that to what I needed. Thanks again!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top