+ Reply to Thread
Results 1 to 3 of 3

Help editing VBA code

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    05-07-2013
    Location
    NY
    MS-Off Ver
    Excel 2010
    Posts
    215

    Help editing VBA code

    Hello everyone,

    I need help modifying the below code. Currently If the value is Blue in one cell, then it puts the word Color in another cell. How do I add onto the code to make it look for Green and Black also?

    So if Blue, Green, or Black then the output is Color


        'Setup for Speed
        '=========================
            Application.ScreenUpdating = False
            Application.Calculation = xlCalculationManual
            
        '=========================
        'Do Work
        '=========================
            For i = 1 To LastRow
                If Range("K" & i).Value = "Blue" Then Range("R" & i).Value = "Color"
            Next i
        
        '=========================
        'Shut down
        '=========================
            Application.ScreenUpdating = True
            Application.Calculation = xlCalculationAutomatic

    Appreciate any help!

  2. #2
    Registered User
    Join Date
    05-12-2016
    Location
    NZ
    MS-Off Ver
    Office 14
    Posts
    41

    Re: Help editing VBA code

    Try:

    Sub test()
        Dim Lastrow As Long
        Lastrow = Range("K1").CurrentRegion.Rows.Count
        For i = 1 To Lastrow
            If Range("K" & i).Value = "Blue" Then
                Range("R" & i).Value = "Color"
            ElseIf Range("K" & i).Value = "Green" Then
                Range("R" & i).Value = "Color"
            ElseIf Range("K" & i).Value = "Black" Then
                Range("R" & i).Value = "Color"
            End If
        Next i
    End Sub

  3. #3
    Registered User
    Join Date
    05-12-2016
    Location
    NZ
    MS-Off Ver
    Office 14
    Posts
    41

    Re: Help editing VBA code

    Or this:

    Sub test()
        Dim Lastrow As Long
        Lastrow = Range("A1").CurrentRegion.Rows.Count
        For i = 1 To Lastrow
            If Range("K" & i).Value = "Blue" Or Range("K" & i).Value = "Green" Or Range("K" & i).Value = "Black" Then
                Range("R" & i).Value = "Color"
            End If
        Next i
    End Sub

+ 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] Code for numbering plus editing
    By JoeDutta in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-29-2014, 01:46 AM
  2. Replies: 0
    Last Post: 05-06-2013, 05:45 AM
  3. Help:in editing code
    By opd in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-12-2013, 02:38 AM
  4. Editing VBA Code - Not working
    By sighlent1 in forum Excel General
    Replies: 2
    Last Post: 12-29-2009, 02:08 PM
  5. Self editing code..?
    By Arne Hegefors in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-28-2006, 11:05 AM
  6. [SOLVED] Editing VB Code with VB
    By Simon Shaw in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-25-2005, 03:05 PM
  7. stubborn Excel crash when editing code with code, one solution
    By Brian Murphy in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-20-2005, 02:06 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