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
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
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 assistedor failed to assist you
I welcome your Feedback.
Hi, I think the following does what you want. Run the 'CopyRecordsMain' procedure - it will automatically call the other one.Originally Posted by das15hild
![]()
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
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks