+ Reply to Thread
Results 1 to 3 of 3

Excel Macro to perform copy and paste and Loop

  1. #1
    Registered User
    Join Date
    11-23-2011
    Location
    london
    MS-Off Ver
    Excel 2003
    Posts
    2

    Lightbulb Excel Macro to perform copy and paste and Loop

    Hi,

    I am new the excel VBA, and would appreciate all the help i can get from you guys and girls. I basically want my macro to copy my first active cell (E31) and paste into pre-define cell (this cell would never change, defined as "TRADE" ) where all the pre deteremine calculation is based off it. And then Macro will just do a refresh of the selected range (defined as REFRESH and REFRESH_MODEL). Once this is done, i want to ask my macro to copy a 3 different cells (the cells for this will never change, cell "TRADE", E23 & 24) and paste into F31 to H31 respectively. Once this is done, I want it to loop and repeat the process, but this time rather than paste into F31 to H31, I want it to paste into next row (e.g. F32 to H32). And then continue to loop until the list of information (Column E31:36) is reached the end.

    I have paste my code for you below, any suggestion would be highly appreciated.





    ...............................................................................................................
    Sub Macro10()
    '
    ' Macro10 Macro
    '

    '
    Dim rowNum As Integer, colNum As Integer, currCell As Range

    rowNum = ActiveCell.Row
    colNum = ActiveCell.Column

    Set currCell = ActiveSheet.Cells(rowNum, colNum)

    Do Until ActiveCell.Value = ""
    ActiveCell.Offset(0, 0).Select

    Selection.Copy
    Application.Goto Reference:="TRADE"
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False

    Application.Goto Reference:="REFRESH"
    Application.Run "OnRangeCalcKey"

    Application.Goto Reference:="REFRESH_MODEL"
    Application.Run "OnRangeCalcKey"

    Application.Goto Reference:="TRADE"
    Application.CutCopyMode = False
    Selection.Copy
    Range("F31").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False

    Range("E23").Select
    Application.CutCopyMode = False
    Selection.Copy
    Range("G31").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False

    Range("E24").Select
    Application.CutCopyMode = False
    Selection.Copy
    Range("H31").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    ActiveCell.Offset(1, -3).Select

    rowNum = rowNum + 1
    Set currCell = ActiveSheet.Cells(rowNum, colNum)

    Loop

    End Sub

  2. #2
    Registered User
    Join Date
    11-23-2011
    Location
    london
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: Excel Macro to perform copy and paste and Loop

    Sorry, forgot to tell you what is my problem.

    The code I put together currently only work for the first time, as I have set it to paste cell to F31 to H31. I am having trouble to make it to understand, I want it post to the next row.

    Thank you very much

  3. #3
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Excel Macro to perform copy and paste and Loop

    Hi Cyrus... Welcome to the forum.

    Be sure to read through the Forum Rules so you can use and follow them effectively.

    For instance, you'll need to EDIT that post above and put code tags around that code you used. (Like shown in my signature)

    Fix that and then I'll show you how to use your loop to offset your paste commands.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

+ 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