+ Reply to Thread
Results 1 to 4 of 4

Trying to assign a value to cells based off of predetermined criteria

  1. #1
    Registered User
    Join Date
    01-16-2015
    Location
    Irvine, CA
    MS-Off Ver
    2007
    Posts
    7

    Trying to assign a value to cells based off of predetermined criteria

    Hello all,
    I am a first time poster, and would really appreciate your help.

    I am relatively new to using VBA and I have a question regarding a problem I encountered at work regarding a macro I am trying to create that would help me out at work and save me days of work down the road.
    I have a large subset of data that I would like to assign values to cells in column C based on criteria in the Column D.

    Column D contains company names, and I would like Column C to display the value Ts, Id, BI based on the following criteria.

    Ts = company name appearing less than or equal to 250 times in the data, and “Mr” or “Mrs” does not appear in the company name.

    ID – appears less than or equal to 2 times in the data, and includes “Mr” or “Mrs”.

    Bi – Company name appears more than 250 times.

    I know I have to work with if statements, but the fact that I am also looking for duplicates is really throwing me off. Your help is greatly appreciated.

    Thank you for your help,

    Nic

  2. #2
    Registered User
    Join Date
    01-16-2015
    Location
    Irvine, CA
    MS-Off Ver
    2007
    Posts
    7

    Re: Trying to assign a value to cells based off of predetermined criteria

    here is what I have currently, however I need it to find if column D contains "Mr" or "Mrs" anywhere in the cell which this code does not do. Another problem is that my macro replaces the value in Column D instead of placing it in Column C.

    Sub Cosignee_identity()
    Dim ws As Worksheet
    Dim cell As Range
    Dim myrng As Range
    Dim lastCell As Range

    Set ws = ThisWorkbook.Sheets("Sheet1")
    Set myrng = ws.Range("D2:D" & Range("D" & ws.Rows.Count).End(xlUp).Row)
    With myrng
    Set lastCell = .Cells(.Cells.Count)

    For Each cell In myrng
    If Application.WorksheetFunction.CountIf(myrng, cell) < 250 Then
    If cell.Value <> "Mr" Or cell.Value <> "Mrs" Then
    cell = "Ts"
    Else
    cell = "Id"
    End If

    Else
    cell = "Bi"

    End If

    Next

    End With
    Last edited by sclog; 01-16-2015 at 06:02 PM.

  3. #3
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Trying to assign a value to cells based off of predetermined criteria

    Hello sclog,

    Welcome to the forum!
    In cell C2 and copied down, give this formula a try:
    Please Login or Register  to view this content.
    Hope that helps,
    ~tigeravatar

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  4. #4
    Registered User
    Join Date
    01-16-2015
    Location
    Irvine, CA
    MS-Off Ver
    2007
    Posts
    7

    Re: Trying to assign a value to cells based off of predetermined criteria

    Thank you for replying tigeravatar. This formula worked for Ts, and Bi, which was a huge help. But it doesn't seem to work for the cells labeled Id.

    I was thinking about using the Instr function in my macro to help with that. Do you think that could solve my issue? Or should I just add more to the formula you provided?

    EDIt: Nevermind I am clearly wasn't paying attention it works fine. Thank you TigerAvatar.
    Last edited by sclog; 01-16-2015 at 06:23 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. [SOLVED] Assign Yes/No to Cell Based on Meeting Some Criteria
    By chicity26 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-25-2014, 10:39 AM
  2. [SOLVED] Copy and paste row from different tab based on 2 different criteria, assign to button
    By AndrewL in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-09-2014, 12:55 AM
  3. Assign String Value Based On Criteria
    By rtabaldi in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 03-03-2014, 10:32 AM
  4. Inserting text based on a predetermined criteria early in the macro
    By MonkeyFlyer in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-30-2012, 06:06 PM
  5. [SOLVED] saving file name based on value in predetermined cell
    By jatman in forum Excel General
    Replies: 5
    Last Post: 05-24-2006, 08:36 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