Consulting

Results 1 to 5 of 5

Thread: Excel VBA cut, paste, delete process.

  1. #1
    VBAX Newbie
    Joined
    May 2017
    Posts
    2
    Location

    Excel VBA cut, paste, delete process.

    Hi there,

    I am relatively new to VBA and i have come across something that i hope is simple however i have got totally stuck on .

    I want to cut and paste the data which appears as in table 1 to appear as in table 2 shown below. This includes deleting the two blank rows which will be created.

    ((28264) CAMARA) Data Data
    ghost
    popstick
    ((92491) App) Data Data
    sole
    heel
    ((96742) New) Data Data

    Table1

    ((28264) CAMARA) ghost popstick Data Data
    ((92491) App) sole heel Data Data
    ((96742) New) Shoe Chair Data Data

    Table 2

    I have managed to do this once with the following macro, however, obviously this wont work its way through all of the data ending when the entire row is blank.

    Sub move_2()
    Range("A2").Select
    Selection.Cut
    Range("B1").Select
    ActiveSheet.Paste
    Rows("2").Select
    Selection.Delete Shift:=x1Up
    Range("A2").Select
    Selection.Cut
    Range("C1").Select
    ActiveSheet.Paste
    Rows("2").Select
    Selection.Delete Shift:=x1Up
    End Sub
    If someone could help it would be most appreciated.

    Thanks,

    Andy.
    Last edited by Paul_Hossler; 05-29-2017 at 07:52 AM.

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    One way
    Sub Test()
    Dim r As Range, cel As Range
    Set r = Cells(1, 1).CurrentRegion
    For Each cel In r
    If Left(cel, 2) = "((" Then
    cel.Offset(1).Cut cel.Offset(, 1)
    cel.Offset(2).Cut cel.Offset(, 2)
    End If
    Next
    r.SpecialCells(xlCellTypeBlanks).EntireRow.Delete
    End Sub
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,729
    Location
    Hi Andy --

    If you use the [#] icon it will insert [ CODE ] tags and you can paste your macro(s) between them

    It helps set the code off and does a little formatting



    Also, you can browse the FAQs http://www.vbaexpress.com/forum/faq.php to learn more about the forum and some important rules
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  4. #4
    VBAX Newbie
    Joined
    May 2017
    Posts
    2
    Location
    spot on!

    the delete line didn't want to work for some reason, so i substituted the below and it works a charm! Thanks dude

    [Range("A:A").SpecialCells(xlCellTypeBlanks).EntireRow.Delete]

  5. #5
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    There are many ways to select a range. If you find an issue, try highlighting the range to check it is what you are after as you step through the code
    Set r = Cells(1, 1).CurrentRegion
    r.Interior.ColorIndex = 6
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Tags for this Thread

Posting Permissions

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