Results 1 to 2 of 2

Thread: INDEX formula not working

  1. #1
    Junior Member SaburaZera's Avatar
    Join Date
    May 2014
    Posts
    3
    Rep Power
    0

    INDEX formula not working

    Hello,

    may I ask you for your help with following code? I have been struggling for some hours and now I seem to be lost completely.

    What I am trying to do: I have a table with some document details starting the area from A6 to K6 and with variable count of rows. I need to choose randomly 20% of them and put an "X" in the column L. My approach is following:

    Code:
     'In the column L, put a formula which will read the randomly chosen document numbers (from column P) and put an "X" when found
        With Sheets("Sheet3")
            lngLastRow = .Cells(.Rows.Count, 2).End(xlUp).Row
            .Range("L6:L" & lngLastRow).FormulaR1C1 = "=IFERROR(IF(VLOOKUP(RC[-7],C[4],1,0)=RC[-7],""X"",""""),"""")"
    
        
        'Copy the document numbers from the column E into the available column N
            .Columns("E:E").Select
            Selection.Copy Destination:=Columns("N:N")
            
    
         'Use RAND formula and paste it as a value
            .Range("O6:O" & lngLastRow).FormulaR1C1 = "=RAND()"
            .Columns("O:O").Select
            Selection.Copy
            Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
            Application.CutCopyMode = False
        End With
        
    
        'Use Index formula to determine the random values
        With Sheets("Sheet3")
            lngLastRow = .Cells(.Rows.Count, 2).End(xlUp).Row
            .Range("P6").Select
            .Range("P6:P" & lngLastRow).FormulaR1C1 = "=INDEX(R6C14:R & lngLastRow,RANK(RC[-1],R6C15:R & lngLastRow))"
            End With
    I always get stuck on the last line:
    Code:
     .Range("P6:P" & lngLastRow).FormulaR1C1 = "=INDEX(R6C14:R & lngLastRow,RANK(RC[-1],R6C15:R & lngLastRow))"
    I really don't know what is wrong. Can you please help me?
    Thank you very much, SaburaZera
    Sharing the knowledge is the best gift ever given. Thank you.

  2. #2
    Administrator Admin's Avatar
    Join Date
    Mar 2011
    Posts
    1,123
    Rep Power
    10
    Try

    Code:
    .Range("P6:P" & lngLastRow).FormulaR1C1 = "=INDEX(R6C14:R" & lngLastRow & "C14,RANK(RC[-1],R6C15:R" & lngLastRow & "C15,0))"
    Cheers !

    Excel Range to BBCode Table
    Use Social Networking Tools If You Like the Answers !

    Message to Cross Posters

    @ Home - Office 2010/2013/2016 on Win 10 (64 bit); @ Work - Office 2016 on Win 10 (64 bit)

Similar Threads

  1. Replies: 2
    Last Post: 03-03-2014, 09:23 AM
  2. Replies: 2
    Last Post: 07-31-2013, 09:59 PM
  3. Replies: 7
    Last Post: 07-26-2013, 06:34 PM
  4. Staffing Scheduling HELP Match/Index
    By mgelston in forum Excel Help
    Replies: 2
    Last Post: 06-20-2013, 01:09 AM
  5. Index Sheets with Shapes and Hyperlink
    By TomyLee in forum Excel Help
    Replies: 9
    Last Post: 09-04-2012, 10:52 PM

Posting Permissions

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