+ Reply to Thread
Results 1 to 3 of 3

relative versus specific cells in macros/vba

  1. #1
    Stutsman
    Guest

    relative versus specific cells in macros/vba

    A macro I'm trying to write has to include a "copy-find-paste-modify" string,
    but I don't know how to generalize the active cell choice to be dependant
    upon the results of the "find" rather than a specific cell typed in vba.

    So, how do I write "find cell, move four cells to the right of found cell,
    modify that cell" rather than, "move to r1c1, modify?" I'm looking
    essentially for a variable plug within r1c1 rather than a specific grid
    placement.

  2. #2
    Die_Another_Day
    Guest

    Re: relative versus specific cells in macros/vba

    Dim fCell as Range
    Set fCell = Cells.Find(What:=SearchText, After:=StartCell,
    LookIn:=xlFormulas, _
    LookAt:=xlWhole, SearchOrder:=xlByRows, _
    SearchDirection:=xlNext, MatchCase:=True).Offset(0,4)
    fCell = "Hello From Iowa"

    HTH

    Die_Another_Day
    Stutsman wrote:
    > A macro I'm trying to write has to include a "copy-find-paste-modify" string,
    > but I don't know how to generalize the active cell choice to be dependant
    > upon the results of the "find" rather than a specific cell typed in vba.
    >
    > So, how do I write "find cell, move four cells to the right of found cell,
    > modify that cell" rather than, "move to r1c1, modify?" I'm looking
    > essentially for a variable plug within r1c1 rather than a specific grid
    > placement.



  3. #3
    JE McGimpsey
    Guest

    Re: relative versus specific cells in macros/vba

    One slight modification that makes things a bit more robust:

    Dim fCell As Range
    Set fCell = Cells.Find(What:=SearchText, _
    After:=StartCell, _
    LookAt:=xlWhole, _
    LookIn:=xlFormulas, _
    SearchOrder:=xlByRows, _
    SearchDirection:=xlNext, _
    MatchCase:=True)
    If fCell Is Nothing Then
    Msgbox SearchText & " was not found."
    Else
    With fCell.Offset(0, 4)
    .Value = .Value & " modified"
    End With
    End If



    In article <[email protected]>,
    "Die_Another_Day" <[email protected]> wrote:

    > Dim fCell as Range
    > Set fCell = Cells.Find(What:=SearchText, After:=StartCell,
    > LookIn:=xlFormulas, _
    > LookAt:=xlWhole, SearchOrder:=xlByRows, _
    > SearchDirection:=xlNext, MatchCase:=True).Offset(0,4)
    > fCell = "Hello From Iowa"
    >
    > HTH
    >
    > Die_Another_Day
    > Stutsman wrote:
    > > A macro I'm trying to write has to include a "copy-find-paste-modify"
    > > string,
    > > but I don't know how to generalize the active cell choice to be dependant
    > > upon the results of the "find" rather than a specific cell typed in vba.
    > >
    > > So, how do I write "find cell, move four cells to the right of found cell,
    > > modify that cell" rather than, "move to r1c1, modify?" I'm looking
    > > essentially for a variable plug within r1c1 rather than a specific grid
    > > placement.


+ 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