Results 1 to 3 of 3

Thread: Creating macro to perform certain actions based on cell contents

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2008
    Posts
    7

    Creating macro to perform certain actions based on cell contents

    I'm trying to figure out how to develop a macro to analyze the content of a cell and perform different actions based on what is in the cell. To be more specific, let's say I want the macro to go to cell B2 and determine what is in that cell. If it determines that the cell contains the letter A then I want to perform a certain action. However, if it contains the letter B I want it to perform a different action. How would I do this?

  2. #2
    PowerPoster jdc2000's Avatar
    Join Date
    Oct 2001
    Location
    Idaho Falls, Idaho USA
    Posts
    2,526

    Re: Creating macro to perform certain actions based on cell contents

    Simple sample code:

    Code:
    Sub CellCheckProc()
    
        If Sheet1.Cells(1,1) = "A" Then
            ' Put your code here for A action
        End If
    
        If Sheet1.Cells(1,1) = "B" Then
            ' Put your code here for B action
        End If
    
        ' Etc., etc.
    
    End Sub

  3. #3
    Fanatic Member
    Join Date
    Apr 2008
    Location
    Kent, England
    Posts
    713

    Re: Creating macro to perform certain actions based on cell contents

    You can use the simple Between, And & Or commands as well. all work the same. how many cells are you looking at working with? is it one or two specific cells or is it a range?
    "Wisdom is only truly achieved, when you realise you dont know everything" ... I must be a genius because I always have to ask stupid questions...

    Pointing an idiot like me in the right direction, is always appreciated by the idiot, explaining how to do what you have pointed the idiot to, is appreciated even more. I apologise to all experienced coders who will think I am an idiot, you are right, I am an idiot, but I am an idiot who is trying to learn

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width