View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Howard Howard is offline
external usenet poster
 
Posts: 536
Default Adjust code to run anywhere on sheet

On Saturday, May 18, 2013 3:33:27 PM UTC-7, Howard wrote:
This code works fine on a list with a Header in column A.

Copies the Header across the same row, starting 1 column to the right for as many columns as there are items in the list.

Cuts the items in the list to the right on a "slant" 1 column over and 1 row down until end of list.



So now the OP says the list will not always be in the same range but wants the code to do as it does here as I have posted. The lists to processed will be in different columns and not always starting at row 1.



I tried using 'For Each c In Selection' but I cannot figure out how to identify the header in the Selection to copy across as needed.



Thanks.

Howard



Option Explicit



Sub cLant()



Dim c As Range

Dim i As Long

Dim rCt As Range



Set rCt = Range("A2:A" & Range("A" & Rows.Count).End(xlUp).Row)



i = 0

For Each c In rCt

c.Cut c.Offset(, i)

Range("A1").Copy Range("A1").Offset(, i)

i = i + 1

Next



End Sub


Small correction:

<Copies the Header across the same row, starting 1 column to the right for as many columns as there are items in the list.

Actually, if list starts in A1, then A1 is the anchor cell and all is displaced from A1. Put a few items in A1 to A5, run code will be a better explanation.

Howard