troubleshooting Question

Would like to understand some excel vba code

Avatar of phoffric
phoffric asked on
Microsoft OfficeMicrosoft ExcelVBA
4 Comments2 Solutions216 ViewsLast Modified:
The code is taken from this post.
https://www.experts-exchange.com/questions/29065786/Spreadsheet-smart-automated-copying-from-one-sheet-to-another.html#a42351651

Option Explicit

Sub CompareInterpolation()
    Dim wsOriginal As Worksheet, wsInterpol As Worksheet
    Dim rwOriginal As Long, rwOriginalMax As Long
    Dim rwInterpol As Long, rwInterpolMax As Long
    Dim arOriginal() As Variant, arInterpolData() As Variant, arInterpolResult() As Variant
    Const Limit As Single = 0.02
    
    Set wsOriginal = Worksheets("Original Data")
    Set wsInterpol = Worksheets("Intepolation")
    rwOriginalMax = wsOriginal.Range("A1").CurrentRegion.Rows.Count
    rwInterpolMax = wsInterpol.Range("A1").CurrentRegion.Rows.Count
    arOriginal = wsOriginal.Range("A1:E" & rwOriginalMax)
    arInterpolData = wsInterpol.Range("A1:B" & rwInterpolMax)
    wsInterpol.Range("K2:O" & rwInterpolMax).ClearContents
    arInterpolResult = wsInterpol.Range("K1:O" & rwInterpolMax)
    
    For rwInterpol = 2 To rwInterpolMax
        For rwOriginal = 2 To rwOriginalMax
            If Abs(Round(arInterpolData(rwInterpol, 1), 3) - arOriginal(rwOriginal, 1)) <= Limit _
             And Abs(Round(arInterpolData(rwInterpol, 2), 3) - arOriginal(rwOriginal, 2)) <= Limit Then
                arInterpolResult(rwInterpol, 1) = arOriginal(rwOriginal, 1)
                arInterpolResult(rwInterpol, 2) = arOriginal(rwOriginal, 2)
                arInterpolResult(rwInterpol, 3) = arOriginal(rwOriginal, 3)
                arInterpolResult(rwInterpol, 5) = arOriginal(rwOriginal, 5)
                Exit For
            End If
        Next rwOriginal
    Next rwInterpol
    wsInterpol.Range("K1:O" & rwInterpolMax) = arInterpolResult
End Sub
ASKER CERTIFIED SOLUTION
Mike in IT
IT System Administrator
Join our community to see this answer!
Unlock 2 Answers and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros