Using a Loop to Assign and Complain Variables in an Array

opaquefruitcake

New Member
Joined
Jan 6, 2019
Messages
2
Hey,

I'm writing a program in vba for work that I want to take the data from each row in columns a and b, then combine that information into a string variable that's part of an array, then check to see whether that same combination appears again. At the moment I'm having trouble with creating and assigning the variable into an array. Here's whag I have so far:

Private Sub strtButton_Click

Dim lastRow As Integer
Dim i As Long
Dim fullValue() As String

lastRow = Cells(Rows.Count, 1).End(x1Up).row

For i = 1 To lastRow

fullValue(i) = ThisWorkbook.Sheets(Sheet1).Range("A" & i & "B" & i)


Next i


I was planning to maybe use the match function after this to test each variable against each other and then change the color of the row those numbers appear in depending on the result. I figured that since i should advance in the same orders of the rows I could use that to identify what is what down the line. Currently I cannot get past the initial loop to assign everything. I'm new to vba and excel so I apoligize if this whole idea is completely crazy. Thanks in advance for sny insight you may be able to offer.
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
There are faster ways to do this, but given this is a coding learning exercise, you could also make just a couple of changes to your code:

Code:
Private Sub strtButton_Click()

    Dim lastRow As Integer
    Dim i As Long
    Dim fullValue() As String
    
    lastRow = Cells(Rows.Count, 1).End(xlUp).Row
    ReDim fullValue(1 To lastRow)
    
    For i = 1 To lastRow
        fullValue(i) = Worksheets("Sheet1").Range("A" & i) & Worksheets("Sheet1").Range("B" & i)
    Next i

End Sub

Note the x-ell-up, not x-one up!
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,728
Members
448,987
Latest member
marion_davis

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