Results 1 to 11 of 11

Macro - question about command line

Threaded View

  1. #1
    Registered User
    Join Date
    11-03-2012
    Location
    CO, USA
    MS-Off Ver
    Excel 2013
    Posts
    26

    Macro - question about command line

    I have a macro that someone built from an example worksheet (below), which I need to customize for my actual worksheet. Can someone please tell me what the following command line does and very generally how "ii" gets used in the rest of the macro, so I know what I need to change: For ii = 2 To 4

    Worksheet: Excel category example.xlsx

    (The macro, copied below, reads the values in columns B, C and D; assigns a category and places it in column E. The actual worksheet has many more rows and columns.)

    Thank you!
    Lis

    Macro:
    Public Sub ProcessData()
    'add more to categories in a comma delimited lists
    Const CAT_CARS As String = "Honda,"
    Const CAT_VEG As String = "Celery,Lettuce,"
    Const CAT_FRUIT As String = "Apple,Mango,"
    Dim Lastrow As Long
    Dim i As Long, ii As Long
    
       Application.ScreenUpdating = False
       
       With ActiveSheet
       
           Lastrow = .UsedRange.Rows.Count
           For i = 2 To Lastrow
           
             For ii = 2 To 4
             
             If .Cells(i, ii).Value <> "" Then
             
             If InStr(CAT_CARS, .Cells(i, ii).Value & ",") > 0 Then
             
             .Cells(i, "E").Value = "Car"
             Exit For
             
             ElseIf InStr(CAT_VEG, .Cells(i, ii).Value & ",") > 0 Then
             
             .Cells(i, "E").Value = "Veggie"
             Exit For
             
             ElseIf InStr(CAT_FRUIT, .Cells(i, ii).Value & ",") > 0 Then
             
             .Cells(i, "E").Value = "Fruit"
             Exit For
             End If
             End If
             Next ii
           Next i
       End With
       
       Application.ScreenUpdating = True
    End Sub
    Last edited by Lis7; 06-28-2013 at 06:03 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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