HeatherD
HeatherD

Reputation: 67

Concatenating with Case Statement

I'm trying to concatenate Column C and Column H into Column F where it meets certain conditions. I want to concatenate Column C where it equals "FS_Tier_1" with Column H where it equals "FS_CAP_1_001" into Column F (below the first line "FS_Tier_1"), until Column H reaches "FS_CAP_1_002".

This is what my data looks like:

enter image description here

I've searched a lot of vba code but cannot find something that quite fits what I'm trying to accomplish. I mainly work in SQL Server, so I'm new to vba. I've tried to use the WHERE clause but haven't been able to make it work.

Sub Concat_ParentCode_Cap1()

With Worksheets("PD Code Structure")

Dim ParentCode As Range
Dim TierCode As String
Dim CapCode As String

TierCode = "FS_Tier_1"
CapCode = "FS_CAP_1_001"
ParentCode = Range("F2:F24")

    Select Case CapCode
        Case "FS_CAP_1_001"
            ParentCode = TierCode & " . " & CapCode



    End Select
End With
End Sub

I keep getting the error message: "Object variable or with block variable not set."

I'd like my data to look like the following:

enter image description here

Upvotes: 0

Views: 108

Answers (1)

Alex de Jong
Alex de Jong

Reputation: 1267

You have to Set the range:

Set ParentCode = Range("F2:F24").

Upvotes: 1

Related Questions