+ Reply to Thread
Results 1 to 7 of 7

Macro Origin Problem

Hybrid View

  1. #1
    Registered User
    Join Date
    01-08-2005
    Posts
    6

    Macro Origin Problem

    I recorded a macro that copies cells B2:B8 and then pastes them in cells A3:A9. Now I want my macro to start at cell B:11 and paste into A3:A19. I highlight cell B11 and start the macro but instead of applying the macro to the new cell range, it goes back and repeats the B2:B8 copy to A3:A9. How to I change the origin or starting point of the macro?

    Thanks
    M

  2. #2
    Forum Contributor
    Join Date
    11-09-2004
    Posts
    451
    Can you paste your recorded macro

  3. #3
    Registered User
    Join Date
    01-08-2005
    Posts
    6
    Thanks! What I want to do is make the ranges variable - I think...

    ' Keyboard Shortcut: Ctrl+z
    '
    Range("C48:C49").Select
    Selection.Copy
    Range("A50").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    Range("A50").Select
    Application.CutCopyMode = False
    Selection.Copy
    Range("A51:A53").Select
    ActiveSheet.Paste
    Range("D48:D49").Select
    Application.CutCopyMode = False
    Selection.Copy
    Range("B50").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    Range("B50").Select
    Application.CutCopyMode = False
    Selection.Copy
    Range("B51:B53").Select
    ActiveSheet.Paste
    End Sub

  4. #4
    Forum Contributor
    Join Date
    11-09-2004
    Posts
    451
    I am not able to understand what you are trying to do.

    You want to copy b2:b8 and then paste to cell a3:a9, You want to start at cell b:11(what is b:11) and paste into a3:a19.

  5. #5
    Registered User
    Join Date
    01-08-2005
    Posts
    6
    Maybe a better way of explaining would be a different example. Say I want change the case, apply a function and delete a space to a value within in a cell. I record a macro. Now I want to apply that macro to several other cells because I don't want to repeat the process over and over. I am not sure it can be done.

  6. #6
    Forum Contributor
    Join Date
    11-29-2003
    Posts
    1,203
    One thing you can do is to replace all cell references with:
    ActiveCell.

    Replace all range references with:
    Selection

    There is a problem, of course, with a cut and paste because you have to tell Excel where to paste.

    If you always want the offset to be the same then you could use something like this:

    Selection.Copy
    ActiveCell.Offset(10, 0).Activate
    ActiveSheet.Paste

    The "Offset(10, 0)" would offset DOWN 10 rows. If you want to offset columns, then it would be something like "Offset(0, 10)" to move 10 columns to the RIGHT. If you want to offset UP by 10 rows, it would be "Offset(-10, 0)". Et cetera.

    Now then, if you want to be able to use variables instead of fixed offsets to specify range and cells, try playing with commands like this:

    myRow = 10
    Range("A" & myRow).Select

    myColumn = 10
    Cells(myRow, myColumn).Activate


    - Pete

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1