3

Hi Please help me with the below,

Sub movedata()

    Call select_data(.Range("B6:B12"))


End Sub


Function select_data(C As Range)

    Worksheets("sheet1").Range("I6:I16") = Worksheets("Sheet1").Range(C).Value

End Function

I can't see where I am going wrong,

Thanks,

2 Answers 2

2

C already is a Range object so there's no need to pass it to the Range() function (which expects a string anyway) to create it.

Change:

Worksheets("sheet1").Range("I6:I16") = Worksheets("Sheet1").Range(C).Value

To:

Worksheets("sheet1").Range("I6:I16") = C
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you, I'm still getting an error for .range("B6:B16") when I call secect_data.... Invalid or unqualified reference
You're using a . before .Range(...) which I assumed was because you had a With Sheets(...) block that you just weren't showing. If you want to pass a range from the active sheet, just remove the . when you pass your range. Otherwise, prefix it with your sheet name: Call select_data(Sheets("mysheet").Range("B6:B12")).
0

You are confusing the range as a Range object with its Address property.

Method 1:

Sub movedata()
    Call select_data(Range("B6:B12").address)
End Sub

Function select_data(C As string)
    with Worksheets("sheet1")
        .Range("I6:I16") = .Range(C).Value
    end with
End Function

Method 2:

Sub movedata()
    Call select_data(Worksheets("sheet1").Range("B6:B12"))
End Sub

Function select_data(C As range)
    C.parent.Range("I6").resize(C.rows.count, C.columns.count) = C.Value
End Function

fwiw, there is going to be some difficulties stuffing B6:B12's values into I6:I16's cells. There seem to be 4 missing values.

Comments

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.