+ Reply to Thread
Results 1 to 4 of 4

"Find" Code

  1. #1
    Forum Contributor
    Join Date
    12-04-2003
    Location
    Burrton, Kansas USA
    MS-Off Ver
    2003
    Posts
    162

    "Find" Code

    Hi!
    I need to find the name that is in range ("name1") in the range ("dataset1") (column A) and then move three columns to the right (column D) and paste-special-values.

    What would the code look like for this?

    Thanks for your time and any help or direction!!

  2. #2
    Jim Jackson
    Guest

    RE: "Find" Code

    This might be workable for you after making necessary modifications to fit
    your needs.


    Sub Replacethem()
    Dim sAddr As String
    Dim rngA As Range, rngB As Range
    Dim rng As Range, cell As Range
    Dim res As Variant

    With Worksheets("Sheet1")

    Set rngB = .Range(.Cells(2, 2), .Cells(2, 2).End(xlDown))
    Set rngC = .Range(.Cells(2, 3), .Cells(2, 3).End(xlDown))

    For Each cell In rngB
    Set rng = rngC.Find(cell.Value, _
    After:=rngC(rngC.Count), _
    LookIn:=xlFormulas, _
    LookAt:=xlPart, _
    SearchOrder:=xlByRows, _
    SearchDirection:=xlNext, _
    MatchCase:=False)

    If Not rng Is Nothing Then
    sAddr = rng.Address

    Do

    rng.Offset(0, 1) = cell.Offset(0, -1).Value
    Set rng = rngC.FindNext(rng)
    Loop While rng.Address <> sAddr

    End If
    Next
    End Sub

    --
    Best wishes,

    Jim


    "Brian Matlack" wrote:

    >
    > Hi!
    > I need to find the name that is in range ("name1") in the range
    > ("dataset1") (column A) and then move three columns to the right
    > (column D) and paste-special-values.
    >
    > What would the code look like for this?
    >
    > Thanks for your time and any help or direction!!
    >
    >
    > --
    > Brian Matlack
    > ------------------------------------------------------------------------
    > Brian Matlack's Profile: http://www.excelforum.com/member.php...fo&userid=3508
    > View this thread: http://www.excelforum.com/showthread...hreadid=562605
    >
    >


  3. #3
    Forum Contributor
    Join Date
    12-04-2003
    Location
    Burrton, Kansas USA
    MS-Off Ver
    2003
    Posts
    162
    Jim:
    Thanks for your response! I'm pretty green about this VBA stuff but I'll try to tweek it to fit my job. I couldn't tell where the res Variant was used in your code. I believe it would be what I was looking for (range name1) in the find part of the code. If you have time to respond I could use the help, if not I do appreciate the input and I'll try to make it work.

    Thanks Again!!

  4. #4
    Jim Jackson
    Guest

    Re: "Find" Code

    Brian,

    I should have taken that out. This was from a larger macro. It has no
    bearing on this routine. Sorry about the confusion.

    Also, there is another change needed. Change "Dim rngA, rngB As Range" to
    "Dim rngB, rngC As Range". rngB will be the text you are looking for in
    rngC.

    Is everything on the same sheet or separate sheets/Workbooks? That will
    make a difference in how it needs to be modified.

    --
    Best wishes,

    Jim


    "Brian Matlack" wrote:

    >
    > Jim:
    > Thanks for your response! I'm pretty green about this VBA stuff but
    > I'll try to tweek it to fit my job. I couldn't tell where the res
    > Variant was used in your code. I believe it would be what I was looking
    > for (range name1) in the find part of the code. If you have time to
    > respond I could use the help, if not I do appreciate the input and I'll
    > try to make it work.
    >
    > Thanks Again!!
    >
    >
    > --
    > Brian Matlack
    > ------------------------------------------------------------------------
    > Brian Matlack's Profile: http://www.excelforum.com/member.php...fo&userid=3508
    > View this thread: http://www.excelforum.com/showthread...hreadid=562605
    >
    >


+ 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