+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    01-11-2010
    Location
    Louisiana, USA
    MS-Off Ver
    Excel 2007
    Posts
    2

    Exclamation Find, Copy, Transpose, Repeat

    I don't know how to write code, so I'm hoping one of you intelligent people can help me out. I've been looking all around for a VBA code that will:

    1 - Search down column A for the word "ADDRESS"
    2 - Once "ADDRESS" is found, I need to copy that cell along with the two cells directly above it (therefore, copying three cells) and transpose these cells' contents to the three columns to the right
    3 - I need this action performed down the entire column, which contains about 18,000 instances of "ADDRESS". The amount of rows between these instances varies and sometimes these in-between rows contain data and other times they don't contain data.

    Thanks for any help you can give me with this.

  2. #2
    Forum Guru davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2007
    Posts
    1,879

    Re: Find, Copy, Transpose, Repeat

    Here ya go:

    Code:
    Public Sub siddharthariver()
    
    Application.ScreenUpdating = False
    For a = 1 To ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row
        If InStr(Cells(a, "A"), "ADDRESS") > 0 Then
            Range(Cells(a - 2, "A"), Cells(a, "A")).Copy
            Cells(a, "B").PasteSpecial Transpose:=True
        End If
    Next a
    Cells(1, 1).Activate
    Application.CutCopyMode = False
    Application.ScreenUpdating = True
    
    End Sub
    Please note "ADDRESS" is case sensitive.
    Is your code running too slowly?
    Does your workbook or database have a bunch of duplicate pieces of data?
    Have a look at this article to learn the best ways to set up your projects.
    It will save both time and effort in the long run!


    Dave

  3. #3
    Forum Guru Palmetto's Avatar
    Join Date
    04-04-2007
    Location
    South Eastern, USA
    MS-Off Ver
    XP, 2007
    Posts
    3,441

    Re: Find, Copy, Transpose, Repeat

    Perhaps this will get you started. Upload a sample workbook of you need more help or this isn't working for you.
    Code:
    Option Explicit
    
    Sub transpose_Data()
    
        Dim c As Range, lrow As Long
        
        lrow = Cells(Rows.Count, 1).End(xlUp).Row
        
        Application.ScreenUpdating = False
        
        On Error Resume Next
        For Each c In Range("A1:A" & lrow)
            If c.Value = "Address" Then
                Range(Cells(c.Row - 2, 1), Cells(c.Row, 1)).Copy
                c.Offset(0, 1).PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
                False, Transpose:=True
            End If
        Next c
        
        Application.ScreenUpdating = True
        Application.CutCopyMode = False
    
    End Sub
    Attached Files Attached Files
    Palmetto

    Do you know . . . ?

    You can leave feedback and add to the reputation of all who contributed a helpful response to your solution by clicking the star icon located at the left in one of their post in this thread.

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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.2.0