+ Reply to Thread
Results 1 to 4 of 4

Search for text and edit neighbouring cell

Hybrid View

  1. #1
    Registered User
    Join Date
    06-28-2017
    Location
    UK
    MS-Off Ver
    2007
    Posts
    2

    Search for text and edit neighbouring cell

    I've been struggling with this one for a while now, having read several posts on here but can't seem to make it work.

    I've got a workbook with several sheets, each of them containing a 'revision number' cell at different locations (e.g. cell X7 contains "Revision:" and cell Y7 the number, e.g. "4"). I'd like to write a macro that searches for the word "Revision:" and adds 1 to the value in the neighbouring cell. So far I've tried the code below, but get the error "Run-time error '13': Type mismatch." What am I doing wrong?

    Thanks!
    Sub RevNumbers()
        
    For Each WS In ActiveWorkbook.Worksheets
        For Each C In WS.Range("A:Z")
            If C.Value = "Revision:" Then
                C.Offset(0, 1).FormulaR1C1 = C.Offset(0, 1).Value + 1
            End If
        Next C
    Next WS
        
    End Sub
    Last edited by graveaj1; 06-28-2017 at 09:47 AM.

  2. #2
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Search for text and edit neighbouring cell

    See if this also errors.
    Sub RevNumbers()
        Dim ws As Worksheet, r As Range, ff As String
        For Each ws In ActiveWorkbook.Worksheets
            Set r = ws.Columns("a:z").Find("Revision:", , , 1)
            If Not r Is Nothing Then
                ff = r.Address
                Do
                    r(, 2).Value = r(, 2).Value + 1
                    Set r = ws.Columns("a:z").FindNext(r)
                Loop While ff <> r.Address
            End If
        Next
    End Sub

  3. #3
    Registered User
    Join Date
    06-28-2017
    Location
    UK
    MS-Off Ver
    2007
    Posts
    2

    Re: Search for text and edit neighbouring cell

    That works perfectly, thanks so much!!!

  4. #4
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Search for text and edit neighbouring cell

    OK 2 things.

    1) Edit your first post and add code tags for vba code
    e.g.
    [code]
    vba code here
    [/code]

    2) Please mark the thread as "SOLVED".

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Sumproduct of column based on text search of neighbouring column
    By anthropormorph in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 01-01-2015, 10:51 AM
  2. Auotmatic highlighting of a neighbouring cell
    By Andy Robertshawe in forum Excel - New Users/Basics
    Replies: 2
    Last Post: 05-27-2014, 05:20 PM
  3. [SOLVED] How to add up cells in a row based on criteria in neighbouring cell
    By bigbrain in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 08-30-2013, 05:55 PM
  4. score explanation in the neighbouring cell
    By polomacnenad in forum Excel - New Users/Basics
    Replies: 2
    Last Post: 02-10-2012, 11:52 AM
  5. macro - search within a cell and edit the text string
    By filo.soph in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-21-2011, 09:19 AM
  6. transferring comments to a neighbouring cell
    By keyes in forum Excel General
    Replies: 3
    Last Post: 09-16-2008, 05:26 PM
  7. Search and Edit cell contents
    By Zooropa in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-26-2006, 04:34 AM

Tags for this Thread

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