+ Reply to Thread
Results 1 to 6 of 6

Change text value randomly based on category

Hybrid View

  1. #1
    Registered User
    Join Date
    04-11-2013
    Location
    Bath, England
    MS-Off Ver
    Excel 2010
    Posts
    27

    Re: Change text value randomly based on category

    Hi,

    Yes, just gender needs to change in the DATA tab.

    Thanks,

    Chris

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Change text value randomly based on category

    Hi,

    Here's one way in the Command buttn click event
    Private Sub Change_Click()
        Dim st As String, ar(), x As Long, y As Long, lRows As Long, c As Long
        st = Sheet2.Range("C3") & Sheet2.Range("C4") & Sheet2.Range("C5")
        lRows = Sheet1.Range("A1").CurrentRegion.Rows.Count - 1
    
        For x = 1 To lRows
            If Sheet1.Range("G2").Cells(x, 1) = st Then
    
                ReDim Preserve ar(c)
                ar(c) = x - 1
                c = c + 1
            End If
        Next x
    
        x = WorksheetFunction.RandBetween(1, c)
        c = 1
        For y = 1 To lRows
            If Sheet1.Range("G2").Cells(y, 1) = st Then
                If c = x Then
                    Sheet1.Range("G" & y + 1) = Replace(st, "Male", "Female")
                    Exit For
                End If
                c = c + 1
            End If
    
        Next y
    
    
    End Sub
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Change text value randomly based on category

    Thanks for the rep.

+ 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. [SOLVED] Change color of chart based on category name
    By Frankximus3 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-03-2017, 06:09 AM
  2. Replies: 1
    Last Post: 12-17-2015, 03:35 AM
  3. Replies: 15
    Last Post: 10-12-2014, 08:53 AM
  4. Replies: 2
    Last Post: 07-15-2014, 08:24 PM
  5. Calculate a weighted average based on text category
    By zbomb2000 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 11-27-2013, 10:07 PM
  6. [SOLVED] Code to randomly select from a list based on Cell text value inptted
    By matrixpom in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-20-2013, 05:57 PM
  7. Sum numbers based on a category of a category
    By mattjac in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 08-09-2012, 11:08 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