1

NOTE: I was able to upload a link to a picture in the comments.

I am using a for loop in an excel macro in an attempt to compile data.

I have the following VBA code:

Sub MoveData()
'
' MoveData Macro
'

'
Dim rng As Range
Set rng = Macro.Application.Range("R1:X1000")
With rng


    For i = 1 To 200
        a = 5 * i
        b = i + 1

        Range(a, 18).Select
        Selection.Copy
        Range(b, 3).Select
        ActiveSheet.Paste

    Next i

End With

End Sub

I get the following error message: Run-time error '424':

Object required

Any clarification would be much appreciated! I've been stumped on this for quite a while!

6
  • are copying and pasting in the same sheet? and these ranges Range(a,18) and Range(b,3) are always the same? Commented Aug 2, 2017 at 13:51
  • try changing this Macro.Application.Range to this ActiveSheet.Range Commented Aug 2, 2017 at 13:55
  • Yes, I am copying and pasting in the same sheet. I will always be copying from columns R:X and pasting in columns C:I Commented Aug 2, 2017 at 13:55
  • @braX when I make that change I get a new error message, Run-time error '1004': Method 'Range' of object '_Global' failed Commented Aug 2, 2017 at 13:56
  • i.sstatic.net/km8Ke.png Here is a link to the screenshots. I want the top photo to look like the bottom photo. Commented Aug 2, 2017 at 13:57

1 Answer 1

1

Try like this and make sure your values are on the activesheet.

Sub MoveData()

    Dim rng As Range

    Set rng = ActiveSheet.Range("R1:X1000")

    With rng
        For i = 1 To 200
            a = 5 * i
            b = i + 1

            Debug.Print "copying from =>" & .Cells(b, 3).Address
            Debug.Print "copyting to =>" & .Cells(a, 18).Address

            Stop 'and take a look at the immediate window
            ' what is there?

            .Cells(b, 3) = .Cells(a, 18)
        Next i
    End With

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

7 Comments

For some reason, that just seemed to remove column t of my data.
@Emma - try to code again. Take a look at the immediate window every time the code stops.
Every round, it prints out: copying from =>$T$2 copying to =>$AI$5
Ok. Then try to adjust it a bit to what you want, by changing a, b, 3 and 18, @Emma
Thank you so much! (I'm new!)
|

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.