0

I have the following code that tries to get a dynamic range and print the values of each cells of the range.

Sub Macro3()

'
    Range("D10").Select
    x = Range(Selection, Selection.End(xlDown)).Select


    For Each cell In x
        MsgBox (cell)
    Next x

End Sub

If I run it however it get a compile error... Any thoughts on what goes wrong here?

2
  • What is the error? Commented Jul 12, 2016 at 10:24
  • Inaccurate reference to variable next (translated from Dutch) Commented Jul 12, 2016 at 10:26

2 Answers 2

1

Try this: (use Set and remove .Select)

Set x = Range(Selection, Selection.End(xlDown))

and Next or Next cell instead of Next x

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

Comments

0
Option Explicit

Sub Macro3()

    Dim x       As Range
    Dim cell    As Range


    Range("D10").Select

    Set x = Range(Selection, Selection.End(xlDown)).Select
    For Each cell In x
        MsgBox (cell)
    Next cell

End Sub

Hi. you need next cell and not next x. Enjoy! :D

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.