+ Reply to Thread
Results 1 to 3 of 3

Simple looping question

  1. #1
    Forum Contributor
    Join Date
    03-16-2004
    MS-Off Ver
    2016
    Posts
    175

    Simple looping question

    I have a spreadsheet from A2 to Z1500 and want to find the word "order form" which then has a number after it. The word "order form" is in various locations all over the spreadsheet with different numbers after each "order form".

    I want to loop thru the entire spreadsheet and copy and paste each instance of "order form"and its unique number to sheet 2 starting at A2 on down.

  2. #2
    Jim Thomlinson
    Guest

    RE: Simple looping question

    This should be close to what you want

    Sub FindOrder()
    Dim wksCopy As Worksheet
    Dim wksPaste As Worksheet
    Dim rngCopy As Range
    Dim rngPaste As Range
    Dim rngCurrent As Range
    Dim rngFirst As Range

    Set wksCopy = Sheets("Sheet1")
    Set wksPaste = Sheets("Sheet2")
    Set rngCopy = wksCopy.Range("A1:Z1500")
    Set rngPaste = wksPaste.Range("A2")

    Set rngCurrent = rngCopy.Find("Order Form")
    If rngCurrent Is Nothing Then
    MsgBox "No Order Forms Found"
    Else
    Set rngFirst = rngCurrent
    Do
    rngCurrent.Copy rngPaste
    rngCurrent.Offset(0, 1).Copy rngPaste.Offset(0, 1)
    Set rngPaste = rngPaste.Offset(1, 0)
    Set rngCurrent = rngCopy.FindNext(rngCurrent)
    Loop Until rngCurrent.Address = rngFirst.Address
    End If
    End Sub

    --
    HTH...

    Jim Thomlinson


    "light" wrote:

    >
    > I have a spreadsheet from A2 to Z1500 and want to find the word "order
    > form" which then has a number after it. The word "order form" is in
    > various locations all over the spreadsheet with different numbers
    > after each "order form".
    >
    > I want to loop thru the entire spreadsheet and copy and paste each
    > instance of "order form"and its unique number to sheet 2 starting at A2
    > on down.
    >
    >
    > --
    > light
    > ------------------------------------------------------------------------
    > light's Profile: http://www.excelforum.com/member.php...fo&userid=7228
    > View this thread: http://www.excelforum.com/showthread...hreadid=396116
    >
    >


  3. #3
    Forum Contributor
    Join Date
    03-16-2004
    MS-Off Ver
    2016
    Posts
    175
    Jim

    Thank-You very much. I notice the macro is reading accross by rows. I would like it to read down by columns. Tried changing the offset but then it has trouble with blank cells. How do I do this adjustment?

+ 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