I have a huge file 15,000+ rows. The file is created possible with mutiple rows based on each "theme" or "item"
Cust Acct Customer Name Rep Code Location Theme Items 121588 Padron Alex 1 Home Casino Forks 121588 Padron Alex 1 Home Casino Confetti 121588 Padron Alex 1 Home Casino Head gear 116384 Meirs Blake 2 Their Village Casino 111387 Campbell RJ 11 Our Town Dance Plates 111693 Ford Steve 12 ABC city Dance Plates 115785 Hastings David 7 Great Suburb Dance Plates 115837 Taco's RJ 11 Our Town DancePlate
I have combined them by hand in the past making each theme and item its own column
Cust Acct Customer Name Rep Code Location Casion Dance Pool Luau Garden Mystery Confetti Streamers Table cloths Knives Glasses Fork Plate Poppers Table Toppers Games Head Gear 106983 Acme Steve 12 ABC city y y 107765 Botox Steve 12 ABC city 111387 Campbell RJ 11 Our Town y Y 111388 Miller RJ 11 Our Town y y y y 111693 Ford Steve 12 ABC city y y y Y 112412 Smith Blake 2 Their Village y y y 112454 Humphrey's RJ 11 Our Town yTo try and automate it I tried create the columns for themes and items using the following code, but it keeps erroring.
I have added a sample file below. Any fix to the code or advice on a better way to accmplish my task would be greatly appreciated.
Code_Goes_Here
Code
Sub array_Match_Data()
Dim rSH As Worksheet
Dim sSh As Worksheet
Set rSH = ThisWorkbook.Sheets("RAW DATA")
Set sSh = ThisWorkbook.Sheets("SEARCH DATA")
Dim rawArray() As String
Dim searchArray() As String
'24 at the end is the number of columns in my raw data worksheet
'22 next row is the number of columns in my search data worksheet
ReDim Preserve rawArray(1 To rSH.Range("A" & Rows.Count).End(xlUp).Row, 1 To 24)
ReDim Preserve searchArray(1 To sSh.Range("A" & Rows.Count).End(xlUp).Row, 1 To 22)
For a = 1 To rSH.Range("A" & Rows.Count).End(xlUp).Row
For b = 1 To 24
rawArray(a, b) = rSH.Cells(a, b)
Next b
Next a
For a = 1 To sSh.Range("A" & Rows.Count).End(xlUp).Row
For b = 1 To 22
searchArray(a) = sSh.Cells(a)
Next b
Next a
Dim holdspace As String
Dim stID As Integer
For a = 2 To UBound(searchArray)
stID = searchArray(a, 1)
For b = 2 To UBound(rawArray)
If rawArray(b, 1) = stID Then
If IsEmpty (rawArray(b, 7)) then
Holdspace = " "
Else
searchArray(a, 5) = rawArray(b, 7)
If IsEmpty (rawArray(b, 8)) then
Holdspace = " "
Else
searchArray(a, 6) = rawArray(b, 8)
If IsEmpty (rawArray(b, 9)) then
Holdspace = " "
Else
searchArray(a, 7) = rawArray(b, 9)
If IsEmpty (rawArray(b, 10)) then
Holdspace = " "
Else
searchArray(a, 8) = rawArray(b, 10)
If IsEmpty (rawArray(b, 11)) then
Holdspace = " "
Else
searchArray(a, 9) = rawArray(b, 11)
If IsEmpty (rawArray(b, 12)) then
Holdspace = " "
Else
searchArray(a, 10) = rawArray(b, 12)
If IsEmpty (rawArray(b, 13)) then
Holdspace = " "
Else
searchArray(a, 11) = rawArray(b, 13)
If IsEmpty (rawArray(b, 14)) then
Holdspace = " "
Else
searchArray(a, 12) = rawArray(b, 14)
If IsEmpty (rawArray(b, 15)) then
Holdspace = " "
Else
searchArray(a, 13) = rawArray(b, 15)
If IsEmpty (rawArray(b, 16)) then
Holdspace = " "
Else
searchArray(a, 14) = rawArray(b, 16)
If IsEmpty (rawArray(b, 17)) then
Holdspace = " "
Else
searchArray(a, 15) = rawArray(b, 17)
If IsEmpty (rawArray(b, 18)) then
Holdspace = " "
Else
searchArray(a, 16) = rawArray(b, 18)
If IsEmpty (rawArray(b, 19)) then
Holdspace = " "
Else
searchArray(a, 17) = rawArray(b, 19)
If IsEmpty (rawArray(b, 20)) then
Holdspace = " "
Else
searchArray(a, 18) = rawArray(b, 20)
If IsEmpty (rawArray(b, 21)) then
Holdspace = " "
Else
searchArray(a, 19) = rawArray(b, 21)
If IsEmpty (rawArray(b, 22)) then
Holdspace = " "
Else
searchArray(a, 20) = rawArray(b, 22)
If IsEmpty (rawArray(b, 23)) then
Holdspace = " "
Else
searchArray(a, 21) = rawArray(b, 23)
If IsEmpty (rawArray(b, 24)) then
Holdspace = " "
Else
searchArray(a, 22) = rawArray(b, 24)
Exit For
End If
Next b
Next a
'Transfer data back
For a = 2 To UBound(searchArray)
For b = 6 To 22
sSh.Cells(a, b).Value = searchArray(a, b)
Next b
Next a
End Sub