1

My code seems to not be working, and I'm not sure why?

Sub Concat()

'Formula to combine the member AC# and Parish Name
Sheets("Risk Partner Data").Select
    Dim ACParish As String, i As String
    Dim rng As Range
    Set rng = Range("A" & Rows.Count).End(x1Up)
    ACParish = rng.Row
    For i = 2 To ACParish
        AcrtiveWorkbook.Sheets("Calc Data").Cells(i, 1) = Cells(i, 1) & Cells(1, 2)
    Next i
End Sub

Says that Compile error, Type mismatch and highlights the "i" in For i = 2

My objective: In another sheet (Risk Partner Data) I have Columns F & E, these are a mixture of text and numbers. I want it to run for all of the active cells in the columns.

I'm new to vba.

1 Answer 1

2

i is being used as an integer in the For ... Next but you've declared it as a string; it should be a Long. Same for ACParish.

There is a typo in AcrtiveWorkbook.

You don't need to .Select a worksheet in order mto access it's values.

Should ... = .Cells(i, 1) & .Cells(1, 2) be ... = .Cells(i, 1) & .Cells(i, 2)?

Sub Concat()

'Formula to combine the member AC# and Parish Name
    Dim ACParish As long, i As long

    with workSheets("Risk Partner Data")
        ACParish  = .Range("A" & Rows.Count).End(xlUp).row
        For i = 2 To ACParish
            .parent.workSheets("Calc Data").Cells(i, 1) = .Cells(i, 1) & .Cells(1, 2)
        Next i
    end with

End Sub
Sign up to request clarification or add additional context in comments.

4 Comments

Hi Jeeped, thank you. Could I please clarify - If my cells contain numbers and letters, is "i" OK to use? Also, if I wish for this to run in a specific column, how would I go about doing that??
i is a row number, not the value of a cell.
I'm getting an error for this "ACParish = .Range("E" & .Row.Count).End(x1Up).Row" what do I do?
x1Up should be xlUp

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.