+ Reply to Thread
Results 1 to 9 of 9

If cell begins with given text then return value

  1. #1
    Spammer
    Join Date
    06-27-2013
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    183

    Thumbs up If cell begins with given text then return value

    Hi Friends,

    I am trying to write macro for the below condition
    If column A begins with “A1 & A2” then Column “B” to be filed with Left(A1,5) and Column “C” to be updated as “Apple” Range is equal to ColumnA

    If column A begins with “B1 & B2” then Column “B” to be filed with Left(A1,5) and Column “C” to be updated as “Banana” Range is equal to Column A

    If column A begins with “O1 & O2” then Column “B” to be filed with Left(A1,5) and Column “C” to be updated as “Orange” Range is equal to Column A

    If column A done not begins with any of the above then Column B & C should be blank

    Kindly help to get VBA code

  2. #2
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: If cell begins with given text then return value


    Hi !

    Where is your try ? Share your code !

  3. #3
    Spammer
    Join Date
    06-27-2013
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    183

    Re: If cell begins with given text then return value

    HTML Code: 

  4. #4
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool

    Let's start with

    Quote Originally Posted by [email protected] View Post
    If column A begins with “A1 & A2” then Column “B” to be filed with Left(A1,5) and Column “C” to be updated as “Apple” Range is equal to ColumnA
    PHP Code: 
             Dim Rg As Range
        
    For Each Rg In Range("A2"Cells(Rows.Count1).End(xlUp))
              If 
    Rg.Value Like "A[12]*" Then
                 Rg
    (12).Resize(, 2).Value = Array(Left(Rg.Value5), "Apple")
    '          elseif …
              
              End If
        Next 
    Do you like it ? So thanks to click on bottom left star icon « Add Reputation » !

  5. #5
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Lightbulb Another way …


    As a beginner starter :

    PHP Code: 
        Dim LVRg As RangeW
            L 
    = [{"A","B","O"}]
            
    = [{"Apple","Banana","Orange"}]
        For 
    Each Rg In Range("A2"Cells(Rows.Count1).End(xlUp))
                
    Application.Match(Left(Rg.Value1), L0)
            If 
    IsNumeric(WThen
                
    If Rg.Value Like "*[12]*" Then Rg(12).Resize(, 2).Value = Array(Left(Rg.Value5), V(W))
            
    End If
        
    Next 
    Do you like it ? So thanks to click on bottom left star icon « Add Reputation » !

  6. #6
    Spammer
    Join Date
    06-27-2013
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    183

    Re: If cell begins with given text then return value

    Thanks!

    One small clarification, if i want to update "V" value ("Apple","Banana","Orange") in "H" column(instead of Column "C") then where is should amend.

  7. #7
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow EZ mod …


    Thanks for the rep' ! Mod for column H :

    PHP Code: 
        Dim LVRg As RangeW
            L 
    = [{"A","B","O"}]
            
    = [{"Apple","Banana","Orange"}]
        For 
    Each Rg In Range("A2"Cells(Rows.Count1).End(xlUp))
                
    Application.Match(Left(Rg.Value1), L0)
            If 
    IsNumeric(WThen
                
    If Rg.Value Like "*[12]*" Then
                   Rg
    (12).Value Left(Rg.Value5)
                   
    Rg(18).Value V(W)
                
    End If
            
    End If
        
    Next 
    Do you like it ? So thanks to click on bottom left star icon « Add Reputation » !

  8. #8
    Spammer
    Join Date
    06-27-2013
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    183

    Re: If cell begins with given text then return value

    Thanks. It is working great. I want to add one more condition like If the column "H" has any blank cells then the above code is to apply on the on blank cells without affecting non blanks cells.

    Is this possible?

  9. #9
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Very EZ mod !


    At beginner level so you should achieved it yourself !

    PHP Code: 
        Dim LVRg As RangeW
            L 
    = [{"A","B","O"}]
            
    = [{"Apple","Banana","Orange"}]
        For 
    Each Rg In Range("A2"Cells(Rows.Count1).End(xlUp))
              If 
    Rg(18).Value "" Then
                    W 
    Application.Match(Left(Rg.Value1), L0)
                If 
    IsNumeric(WThen
                    
    If Rg.Value Like "*[12]*" Then
                       Rg
    (12).Value Left(Rg.Value5)
                       
    Rg(18).Value V(W)
                    
    End If
                
    End If
              
    End If
        
    Next 
    Do you like it ? So thanks to click on bottom left star icon « Add Reputation » !

+ 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] If text string BEGINS with 5 spaces then shift cell to the right
    By Groovicles in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-14-2017, 09:41 AM
  2. Search and Return the value of a cell that begins with specific text?
    By Kirk3737 in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 11-14-2015, 12:35 PM
  3. [SOLVED] Display chosen number if cell text begins with specific letter
    By BPSJACK in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 04-03-2014, 07:12 AM
  4. [SOLVED] if cell BEGINS WITH abc, then return 123, or if cell BEGINS WITH def, then 456, ...
    By Marijke in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 03-29-2013, 11:20 AM
  5. [SOLVED] IF number/text in a cell begins with specific letter, then return desired word
    By BPSJACK in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 01-28-2013, 06:02 AM
  6. [SOLVED] Insert text to cell based on whether the value begins with a letter or number.
    By BPSJACK in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 07-23-2012, 09:57 AM
  7. IF Cell Contains Text That Begins With....
    By sabrefan27 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 06-22-2007, 03:30 AM

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