Concatenate values into range VBA

Drawleeh

New Member
Joined
Sep 2, 2021
Messages
34
Office Version
  1. 2016
  2. 2010
Platform
  1. Windows
Hello, I have the following code that I can't figure out how to adjust -

VBA Code:
Sub SumData()

Dim HSArr(2 To 250) As Variant
Dim HSVal As Long

For HSVal = LBound(HSArr) To UBound(HSArr)
HSArr(HSVal) = Cells(HSVal, 1) & "_" & Cells(HSVal, 2)
Next HSVal


    Const dFormula As String _
        = "=IFERROR(SUMPRODUCT(--(HSArr=I2),D$2:D$250,F$2:F$250),"""")"
    With ThisWorkbook.Worksheets("Sheet1").Range("K2:K250")
        .Formula = dFormula
        .Value = .Value
    End With

End Sub

All I want to do is concatenate column A and column B and then parse that A:B as range into the SUMPRODUCT without having to express the concatenated range onto the worksheet . Currently nothing happens when code is run, what am I doing wrong?
 
Last edited:

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
With this:
VBA Code:
For HSVal = LBound(HSArr) To UBound(HSArr)
HSArr(HSVal) = Cells(HSVal, 1) & "_" & Cells(HSVal, 2)
Next HSVal
I belive HSArr does not save history of previous HSVal
Try to add
Msgbox HSArr(250)
to see the instant result.
 
Upvote 0
My issue is that the array concatenates the 2 values fine, I can take the array and populate it into the column, but I don't know how to express that as a range in the SUMPRODUCT without actually assigning an actual range on the worksheet? Currently the array is storing the data but not in the required format for the SUMPRODUCT to be used. How do I include the first part of my code to work with the second or do I have to do something completely different..?
 
Upvote 0

Forum statistics

Threads
1,224,740
Messages
6,180,678
Members
452,993
Latest member
FDARYABEE

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