+ Reply to Thread
Results 1 to 3 of 3

Find record

Hybrid View

  1. #1
    Registered User
    Join Date
    06-08-2007
    Posts
    1

    Find record

    I already have a macro that finds and copies the first row any record in a column to the next column.

    I require some help to select say DATA CA001/10 in the records and copy to a new column.

    Please refer to the attached example.

    Thanks David
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    If I understand what you are after correctly this macro will do what you want.

    If you require it to search for multiple instances then try activating the do Loop commands that are disabled within the macro
    Dim rngRCJ As Range
    Dim rngData As Range
    
    Set rngData = Cells(Rows.Count, "a")
    With Columns("a:a")
      ' do
       Set rngRCJ = .Find("RECORD PAYMENT_JOURNAL", After:=rngData)
          If rngRCJ Is Nothing Then
             Exit Sub
          End If
          Set rngData = .Find("DATA CA001/10", After:=rngRCJ)
          If Not rngData Is Nothing Then
             Range(rngRCJ.Address, rngData.Address).Offset(0, 1).Value = Range(rngRCJ.Address, rngData.Address).Value
          End If
          
          Set rngRCJ = .Find("RECORD RECEIPT_JOURNAL", After:=rngData)
          If rngRCJ Is Nothing Then
             Exit Sub
          End If
          Set rngData = .Find("DATA CA001/10", After:=rngRCJ)
          If Not rngData Is Nothing Then
             Range(rngRCJ.Address, rngData.Address).Offset(0, 1).Value = Range(rngRCJ.Address, rngData.Address).Value
          End If
       'loop
    End With
    Please Read Forum Rules Before Posting
    Wrap VBA code by selecting the code and clicking the # icon or Read This
    How To Cross Post politely

    Top Excel links for beginners to Experts

    If you are pleased with a member's answer then use the Scales icon to rate it
    If my reply has assisted or failed to assist you I welcome your Feedback.

  3. #3
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464
    Quote Originally Posted by das15hild
    I already have a macro that finds and copies the first row any record in a column to the next column.

    I require some help to select say DATA CA001/10 in the records and copy to a new column.

    Please refer to the attached example.

    Thanks David
    Hi, I think the following does what you want. Run the 'CopyRecordsMain' procedure - it will automatically call the other one.


    Sub CopyRecords(JnlType As String, Rows As Integer)
    Dim rAddress As Range, x As Integer, stJnl As String, stData As String
    
    Set rAddress = Range("A1")
    
    Do
        With Range((rAddress.Offset(1, 0).Address) & ":A100")
            Set rAddress = .Find(JnlType)
            If rAddress Is Nothing Then Exit Sub
            rAddress.Copy Destination:=Range(rAddress.Cells(1, 2), rAddress.Cells(Rows, 2))
            rAddress.Offset(Rows - 2).Copy Destination:=Range(rAddress.Cells(1, 3), rAddress.Cells(Rows, 3))
        End With
    Loop
    
    End Sub
    
    Sub CopyRecordsMain()
    Call CopyRecords("RECORD RECEIPT_JOURNAL", 5)
    Call CopyRecords("RECORD PAYMENT_JOURNAL", 6)
    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