+ Reply to Thread
Results 1 to 4 of 4

macro question - selecting the right column

  1. #1
    Brad
    Guest

    macro question - selecting the right column

    I have information in columns from C to CA that I need to put (cut) into
    column C

    The following macro lacks one item - an ability to keep moving over to the
    correct column and cutting the appropriate items. By this I mean
    Range"D2".select then Range"E2".select ... This process will have to go until
    I reach Range"CA2".select

    Any help would be appreciated

    Sub cutandcopy()
    '
    ' cutandcopy Macro

    '

    '
    Range("D2").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Cut
    Range("C2").Select
    Selection.End(xlDown).Select
    Range("C122").Select
    ActiveSheet.Paste
    Selection.End(xlUp).Select
    Range("E2").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Cut
    Range("C2").Select
    Selection.End(xlDown).Select
    Range("C242").Select
    ActiveSheet.Paste
    End Sub


  2. #2
    Tom Ogilvy
    Guest

    Re: macro question - selecting the right column

    Sub copydata()
    Dim rng as Range, rng1 as Range, cell as Range
    set rng = Range("D2:CA2")
    for each cell in rng
    set rng1 = range(cell,cell.End(xldown))
    if isempty(Range("C2")) then
    rng1.copy Destination:=Range("C2")
    else
    rng1.Copy Destination:=Range("C2").End(xldown)(2)
    end if
    Next
    Range(Range("D2:CA2"), _
    Range("D2:CA2").End(xldown)).ClearContents
    End Sub

    --
    Regards,
    Tom Ogilvy



    "Brad" <[email protected]> wrote in message
    news:[email protected]...
    > I have information in columns from C to CA that I need to put (cut) into
    > column C
    >
    > The following macro lacks one item - an ability to keep moving over to the
    > correct column and cutting the appropriate items. By this I mean
    > Range"D2".select then Range"E2".select ... This process will have to go

    until
    > I reach Range"CA2".select
    >
    > Any help would be appreciated
    >
    > Sub cutandcopy()
    > '
    > ' cutandcopy Macro
    >
    > '
    >
    > '
    > Range("D2").Select
    > Range(Selection, Selection.End(xlDown)).Select
    > Selection.Cut
    > Range("C2").Select
    > Selection.End(xlDown).Select
    > Range("C122").Select
    > ActiveSheet.Paste
    > Selection.End(xlUp).Select
    > Range("E2").Select
    > Range(Selection, Selection.End(xlDown)).Select
    > Selection.Cut
    > Range("C2").Select
    > Selection.End(xlDown).Select
    > Range("C242").Select
    > ActiveSheet.Paste
    > End Sub
    >




  3. #3
    Jim Thomlinson
    Guest

    RE: macro question - selecting the right column

    Give this a try...

    Sub Test()
    Dim rngCurrent As Range
    Dim rngCopy As Range
    Dim rngPaste As Range

    Set rngCurrent = Range("D2")
    Set rngCopy = Range(rngCurrent, Cells(Rows.Count,
    rngCurrent.Column).End(xlUp))
    Set rngPaste = Cells(Rows.Count, "C").End(xlUp).Offset(1, 0)

    Do While rngCurrent.Column < 80
    Set rngCurrent = rngCurrent.Offset(0, 1)
    rngCopy.Cut rngPaste
    Set rngPaste = Cells(Rows.Count, "C").End(xlUp).Offset(1, 0)
    Set rngCopy = Range(rngCurrent, Cells(Rows.Count,
    rngCurrent.Column).End(xlUp))
    Loop
    End Sub
    --
    HTH...

    Jim Thomlinson


    "Brad" wrote:

    > I have information in columns from C to CA that I need to put (cut) into
    > column C
    >
    > The following macro lacks one item - an ability to keep moving over to the
    > correct column and cutting the appropriate items. By this I mean
    > Range"D2".select then Range"E2".select ... This process will have to go until
    > I reach Range"CA2".select
    >
    > Any help would be appreciated
    >
    > Sub cutandcopy()
    > '
    > ' cutandcopy Macro
    >
    > '
    >
    > '
    > Range("D2").Select
    > Range(Selection, Selection.End(xlDown)).Select
    > Selection.Cut
    > Range("C2").Select
    > Selection.End(xlDown).Select
    > Range("C122").Select
    > ActiveSheet.Paste
    > Selection.End(xlUp).Select
    > Range("E2").Select
    > Range(Selection, Selection.End(xlDown)).Select
    > Selection.Cut
    > Range("C2").Select
    > Selection.End(xlDown).Select
    > Range("C242").Select
    > ActiveSheet.Paste
    > End Sub
    >


  4. #4
    Brad
    Guest

    RE: macro question - selecting the right column

    Thank you very much it worked - I will have to study the code to find out
    what it is doing.

    "Jim Thomlinson" wrote:

    > Give this a try...
    >
    > Sub Test()
    > Dim rngCurrent As Range
    > Dim rngCopy As Range
    > Dim rngPaste As Range
    >
    > Set rngCurrent = Range("D2")
    > Set rngCopy = Range(rngCurrent, Cells(Rows.Count,
    > rngCurrent.Column).End(xlUp))
    > Set rngPaste = Cells(Rows.Count, "C").End(xlUp).Offset(1, 0)
    >
    > Do While rngCurrent.Column < 80
    > Set rngCurrent = rngCurrent.Offset(0, 1)
    > rngCopy.Cut rngPaste
    > Set rngPaste = Cells(Rows.Count, "C").End(xlUp).Offset(1, 0)
    > Set rngCopy = Range(rngCurrent, Cells(Rows.Count,
    > rngCurrent.Column).End(xlUp))
    > Loop
    > End Sub
    > --
    > HTH...
    >
    > Jim Thomlinson
    >
    >
    > "Brad" wrote:
    >
    > > I have information in columns from C to CA that I need to put (cut) into
    > > column C
    > >
    > > The following macro lacks one item - an ability to keep moving over to the
    > > correct column and cutting the appropriate items. By this I mean
    > > Range"D2".select then Range"E2".select ... This process will have to go until
    > > I reach Range"CA2".select
    > >
    > > Any help would be appreciated
    > >
    > > Sub cutandcopy()
    > > '
    > > ' cutandcopy Macro
    > >
    > > '
    > >
    > > '
    > > Range("D2").Select
    > > Range(Selection, Selection.End(xlDown)).Select
    > > Selection.Cut
    > > Range("C2").Select
    > > Selection.End(xlDown).Select
    > > Range("C122").Select
    > > ActiveSheet.Paste
    > > Selection.End(xlUp).Select
    > > Range("E2").Select
    > > Range(Selection, Selection.End(xlDown)).Select
    > > Selection.Cut
    > > Range("C2").Select
    > > Selection.End(xlDown).Select
    > > Range("C242").Select
    > > ActiveSheet.Paste
    > > End Sub
    > >


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1