if rows between strings contain value, copy all to adjacent cells

ajm

Well-known Member
Joined
Feb 5, 2003
Messages
2,013
Office Version
  1. 365
Platform
  1. Windows
I am trying to create a macro that will help our accounts team find erroneous postings to a particular journal. the data to search is all contained in Column A and appears in a fairly standardised format.
first line is "VCH", for voucher
second is alpha and numeric string for description
third line is "JNL" or journal
then there are several lines of sub journal description which generally consist of a exact breakdown of the cost element at VCH.

then VCH again and away you go.

HOw can i find those rows which contain the letters "DR" in each of the VCH sub journals?

i found the following piece of code (and my apologies to its author as i can't find the page it came from now) which finds the first instance of a string and then the last instance and copies all the rows in between into an adjacent column. I have been trying to find a way to include the "if it contains DR bit, in between the first and last instance of the search terms, then copy

Code:
Sub x()


    Dim rngTemp As Range
    Dim rngFind As Range
    Dim rngFirst As Range
    Dim rngLast As Range
    Dim strFirstAddress As String
    Dim lngRow As Long

    lngRow = Range("A" & Rows.Count).End(xlUp).Row + 1
    With Range("A:A")
        Set rngFind = .Find("VCH*", .Cells(lngRow, 1), LookIn:=xlValues, lookat:=xlPart)
        MsgBox rngFind
        If Not rngFind Is Nothing Then
            strFirstAddress = rngFind.Address
            
            Set rngFirst = rngFind.Offset(1)
            Set rngTemp = rngFirst
            Set rngFind = .FindNext(rngFind)
         

            Do While Not rngFind Is Nothing And rngFind.Address <> strFirstAddress
                Set rngLast = rngFind
                Set rngTemp = Union(rngTemp, Range(rngFirst, rngLast))
                Set rngFirst = rngFind
                Set rngFind = .FindNext(rngFind)
            Loop
        End If
    End With
  
    If Not rngTemp Is Nothing Then rngTemp.Copy Range("B1")
End Sub
/code]
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
bumpity bump

can anyone suggest anything to get me along with this one. its driving me nuts! as is the accounts person....
 
Upvote 0
can this not be done then??surely there is a way.
 
Upvote 0

Forum statistics

Threads
1,215,880
Messages
6,127,519
Members
449,385
Latest member
KMGLarson

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top