VBA Help - Array Loop Won't Populate Cell????

Johnny Thunder

Well-known Member
Joined
Apr 9, 2010
Messages
669
Office Version
  1. 2016
Platform
  1. MacOS
Hello all,

I have a piece of code that creates an Array with my range of data and looks for a value in Column B, if the value equals a Declared string, then Drop a value in column ("O") if not, just grab the value from Column B and drop that in Column ("O").

The logic of the code seems fine and when hovering over any of my declared values I am seeing all the values I should be seeing, its only when I tell the code to populate column ("O") nothing seems to be happening?

Not sure what the issue is but hopefully someone will spot it.

Code:
'----------------------------------------------------------------------------------------
'--- Using the Group List by Titles tag each record with Unique Name
'----------------------------------------------------------------------------------------
Sub GroupTitles2()


Dim ws1 As Worksheet, ws2 As Worksheet
Dim Count As String, OriginalTitle As String, GroupTitle As String
Dim LastR1 As Long, LastR2 As Long
Dim VarArray As Variant
Dim i As Long, j As Long


Application.ScreenUpdating = False


Set ws1 = Sheets("Download")
Set ws2 = Sheets("Lookup")


LastR1 = ws1.Range("G" & Rows.Count).End(xlUp).Row
LastR2 = ws2.Range("B" & Rows.Count).End(xlUp).Row


For i = 2 To LastR2
    If ws2.Cells(i, 2) <> "" Then
        OriginalTitle = ws2.Cells(i, 2).Value
            GroupTitle = ws2.Cells(i, 3).Value
    End If
            
VarArray = ws1.Range("A2:O" & LastR1).Value


        For j = 1 To UBound(VarArray, 1)
            If VarArray(j, 2) = OriginalTitle Then
                VarArray(j, 15) = GroupTitle     '<-----------------------------------This line won't drop a value?????
            Else
                VarArray(j, 15) = VarArray(j, 2) '<-----------------------------------This line won't drop a value?????
            End If
        Next j


Next i
        
Application.ScreenUpdating = True
        
End Sub
 

Some videos you may like

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
12,593
Office Version
  1. 2007
Platform
  1. Windows
I think I sent you the solution to this thread but in another one of your thread.
The macro I put you uses arrays.
As I mentioned you should give examples to understand the process.
 

Watch MrExcel Video

Forum statistics

Threads
1,108,649
Messages
5,524,068
Members
409,558
Latest member
MarkD018

This Week's Hot Topics

Top