+ Reply to Thread
Results 1 to 4 of 4

VBA - Add a Sequence Number based on Condition

  1. #1
    Registered User
    Join Date
    07-24-2013
    Location
    New Mexico
    MS-Off Ver
    Excel 2007
    Posts
    10

    VBA - Add a Sequence Number based on Condition

    I have a spreadsheet which imports data files, and each file has a cell that has the word "Sample" .
    I would like VBA code to find and replace each instance of the word "Sample" with the 'Title1', then 'Title2', then 'Title3' etc.
    I was working with the code below to try add sequence numbers, but it's not quite working right, and I know the answer is simple.
    Any help would be awesome.



    Sub Numbers()

    Dim ged As Variant
    Dim b As Range


    ged = "Sample"


    For Each b In ActiveSheet.Range("A1:A")
    k = 1
    i = k + 1
    If b.Value = ged _
    Then b.Value = "Title" & i + 1

    Next b

    End Sub

  2. #2
    Registered User
    Join Date
    02-04-2014
    Location
    Hyderabad, India
    MS-Off Ver
    Excel 2010
    Posts
    24

    Re: VBA - Add a Sequence Number based on Condition

    Try the below code.


    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    07-24-2013
    Location
    New Mexico
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: VBA - Add a Sequence Number based on Condition

    Doesn't work, the spreadsheet filters and locks up. Not sure what the issue is, as Excel freezes before debugging.

  4. #4
    Registered User
    Join Date
    02-04-2014
    Location
    Hyderabad, India
    MS-Off Ver
    Excel 2010
    Posts
    24
    Run the code in debug mode and check the value in lastrow variable

    Check column A. Code is expecting to have the "sample" in column A .
    And data in Column A is starting from cell A1 with continuous valueS without blanks



    If possible upload the sample file
    Last edited by KrisSquare; 02-12-2014 at 06:05 PM.

+ 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. auto- sequence number based on another column?
    By maynard in forum Excel General
    Replies: 6
    Last Post: 07-29-2016, 10:31 PM
  2. sequence number based on date
    By denise in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 02-19-2014, 03:09 PM
  3. Replies: 2
    Last Post: 05-19-2013, 03:59 AM
  4. VBA Code To Mirror Cells from one Worksheet to another based on sequence number
    By jarrinsonp in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-29-2010, 06:28 AM
  5. [SOLVED] How do I: Extract column headers based on lowest number in sequence
    By WolfJack in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 06-21-2006, 04:30 PM

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