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

Johnny Thunder

Well-known Member
Joined
Apr 9, 2010
Messages
693
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
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
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.
 
Upvote 0

Forum statistics

Threads
1,224,899
Messages
6,181,629
Members
453,059
Latest member
jkevin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top