Results 1 to 3 of 3

VBA code explanation needed - Sometimes outputs wrong data

Threaded View

  1. #1
    Registered User
    Join Date
    11-26-2011
    Location
    Norway
    MS-Off Ver
    Excel 2007
    Posts
    11

    VBA code explanation needed - Sometimes outputs wrong data

    Hi all

    I have used the below code for a while, but it sometimes outputs values in a cell when its not supposed to.
    i got help creating this code in this forum a while ago

    
    Sub tgr()
        
        Dim rng(1 To 3) As Range
        Dim i As Long
        
        For i = 1 To 3
            Set rng(i) = Intersect(Sheets("KommentarBackup").UsedRange, Sheets("KommentarBackup").Columns(i))
        Next i
        
        With Sheets("Ordre").Range("L4:L" & Sheets("Ordre").Cells(Rows.Count, "A").End(xlUp).Row)
            .Formula = "=IFERROR(INDEX(KommentarBackup!" & rng(3).Address & ",SUMPRODUCT(--(A4=KommentarBackup!" & rng(1).Address & "),--(B4=KommentarBackup!" & rng(2).Address & "),ROW(KommentarBackup!" & rng(3).Address & "))),"""")"
            .Value = .Value
        End With
        
    End Sub
    What this code does is mathing row A and B in sheet "ordre" with row A and B in sheets "kommentarbackup" and
    copies row C from "kommentarbackup" to row L "ordre" in column where both matches.

    I think that my problem is when i have a row A and B that doesnt match - i think in these cases the formula copies the corresponding row anyway - (example : now match row A and B "ordre" row 265 : copies row C "kommentarbackup" row 265 to row L "ordre" row 265. Not sure though

    ill paste the link to my original post for further explanation :
    http://www.excelforum.com/excel-prog...-in-range.html
    Last edited by Biinge; 03-03-2012 at 03:33 PM.

Thread Information

Users Browsing this Thread

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

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