+ Reply to Thread
Results 1 to 6 of 6

Thread: Copying cell values in sheet 1 to cells in sheet 2

  1. #1
    Registered User
    Join Date
    04-22-2011
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    33

    Copying cell values in sheet 1 to cells in sheet 2

    As part of the workbook I have a scenario sheet on sheet2 which is partly dependent on user input values on sheet1. The output of sheet2 is then pasted to the next available row in sheet3. At present I am having to revert back to sheet 1 to change the user values and then back to sheet 2 to run the scenario. These sheet 1 input cells need to remain on sheet1 as they are where users spend most time. I know I could simply record a macro and cut and paste the various cells one by one into sheet1 cells but is there a more elegant coding solution?

    There are only about 8 values to change if that helps.

    Many thanks
    Last edited by coasterman; 12-20-2011 at 02:53 PM.

  2. #2
    Forum Guru mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    2,998

    Re: Copying cell values in sheet 1 to cells in sheet 2

    There might be a more elegant solution, but that solution would be eaiser to find if you recorded the (ugly) macro and posted that.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  3. #3
    Registered User
    Join Date
    04-22-2011
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    33

    Re: Copying cell values in sheet 1 to cells in sheet 2

    That would be more instructive I would have to agree
    Sub LOECalxChangeValues()
    '
    ' LOECalcChangeValues Macro
    '
    
    '
        Application.ScreenUpdating = False
        Sheets("LOETblCalx").Select
        Range("Q11:R14").Select
        Selection.Copy
        Sheets("Home").Select
        Range("F28").Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        Application.CutCopyMode = False
        Sheets("LOETblCalx").Select
        Range("p12").Select
        Selection.Copy
        Sheets("Home").Select
        Range("F19").Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        Application.CutCopyMode = False
        Sheets("LOETblCalx").Select
        Range("P12").Select
        Application.ScreenUpdating = True
         
        
    End Sub
    Last edited by coasterman; 12-20-2011 at 02:36 PM.

  4. #4
    Forum Guru mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    2,998

    Re: Copying cell values in sheet 1 to cells in sheet 2

    With Sheets("LOETblCalx")
        With .Range("Q11:R14")
            Sheets("Home").Range("F28").Resize(.Rows.Count, .Columns.Count).Value = .Value
        End With
        Sheets("Home").Range("F19").Value = .Range("P12").Value
        .Range("P12").Select
    End With
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  5. #5
    Registered User
    Join Date
    04-22-2011
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    33

    Re: Copying cell values in sheet 1 to cells in sheet 2

    Thank you very much for th. I think I can see how I now need to re-write much of the code in my workbook as it contains dozens of Select Copy Paste routines. Hopefully by the end of re-writing I will have a proper feel for the use of With statement in this sort of context.

  6. #6
    Forum Guru mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    2,998

    Re: Copying cell values in sheet 1 to cells in sheet 2

    The imporant part of the code I posted wasn't the use of With..EndWith (although that is a very useful feature of VBA), but removing the Selection makes the code both faster and more robust.

    Select is almost never nessesary.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

+ 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.2.0