+ Reply to Thread
Results 1 to 2 of 2

Excel VBA help copying and pasting text to a new row

Hybrid View

  1. #1
    Registered User
    Join Date
    07-11-2012
    Location
    Maryland
    MS-Off Ver
    Excel 2007
    Posts
    1

    Excel VBA help copying and pasting text to a new row

    Hello Everyone,

    I'm new to Excel VBA would appreciate anyone that is kind enough to help me. I'm trying to write a macro that looks in cell A1:VGH1 for the text "Name:" within the row, then copy that cell and other following cells and paste into a new row. This macro can loop through the row until all instances of the text "Name:" and the following cells are on their own row. Thank you soo much in advance.


    What I have currently.

    Name:xxx From:xxx Name:xxx To:xxx From:xxx Name:xxx: To:xxx

    The result

    Name:xxx From:xxxx
    Name:xxx To:xxx From:xxxx
    Name:xxx To:xxx

  2. #2
    Valued Forum Contributor
    Join Date
    08-06-2013
    Location
    Detroit, Michigan
    MS-Off Ver
    Excel 2013
    Posts
    671

    Re: Excel VBA help copying and pasting text to a new row

    Assuming you have your current text in row 1 and want your results in A2 and down, this code should work.

    Sub Name_Find()
    
    Dim names() As Long
    Set rNa = Range("A1")
    iLoop = WorksheetFunction.CountIf(Rows(1), "Name:*")
    ReDim names(1 To iLoop)
    
     For i = 1 To iLoop
    
    
      Set rNa = Rows(1).Find(What:="Name:", After:=rNa, _
        LookIn:=xlValues, LookAt:=xlPart, _
        SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
        MatchCase:=False)
    
        names(i) = rNa.Column
        Cells(i + 1, 1).Value = rNa
        If i <> 1 Then Cells(i + 1, 2).Resize(1, names(i) - names(i - 1) - 1).Value = Range(Cells(1, names(i - 1) + 1), Cells(1, names(i) - 1)).Value
    
     Next i
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Copying and pasting alternative text of more than one checkbox
    By src16 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-06-2016, 09:15 PM
  2. Syntax Error when copying/pasting text from excel cell to
    By csmiley in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-03-2013, 07:51 PM
  3. Replies: 0
    Last Post: 10-05-2010, 09:08 AM
  4. Copying and pasting multiple text files into different tabs.
    By kingbiscuit in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-05-2008, 01:59 PM
  5. Copying from Excel - pasting in Publisher
    By vman252 in forum Excel General
    Replies: 0
    Last Post: 03-19-2006, 08:01 PM

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