+ Reply to Thread
Results 1 to 6 of 6

(CODE) how to do vba for paste and add values.

Hybrid View

  1. #1
    Registered User
    Join Date
    04-15-2013
    Location
    Toronto
    MS-Off Ver
    Excel 2007
    Posts
    7

    Question (CODE) how to do vba for paste and add values.

    Now i have a new question,

    1.on the first tab "Scenario" ,i want to copy value from F5 and paste it over to B5 of tab"Plan Attributes", then on the plan attributes tab, copy C62 to HJ74 the whole block, paste values to results starting from C2.
    2. then i want to copy value from G5 and paste it over B5 of tab plan attributes, then on the same tab, copy C62 to HJ74 whole block ,and paste add values starting from D2.
    3. then i want to copy value from H5 and paste it over B5 of tab plan attributes, then on the same tab, copy C62 to HJ74 whole block ,and paste add values starting from E2.
    ........do this until we stop at Q5 last value .

    after we finish all values from ROW 5, we start on row 6, the same procedure. unitl we finish on row 51.

    I have the excel sheet.
    Attached Files Attached Files
    Last edited by zhengzhi8806; 07-30-2013 at 02:00 PM.

  2. #2
    Forum Contributor
    Join Date
    05-29-2013
    Location
    MD
    MS-Off Ver
    Excel 365
    Posts
    148

    Re: Help me on this VBA code. Error msg

    Please use the CODE tags when posting code.

    You seem to be missing the final End If, as the For loop is inside the If statement, and the last line is Next.

    If you tabulate your code this doesn't happen so much though

  3. #3
    Registered User
    Join Date
    04-15-2013
    Location
    Toronto
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Help me on this VBA code. Error msg

    sorry, i will change my thread.

    so i should switch end if and next?

  4. #4
    Forum Contributor
    Join Date
    05-29-2013
    Location
    MD
    MS-Off Ver
    Excel 365
    Posts
    148

    Re: (CODE) Help me on this VBA code. Error msg

    Don't switch them, add an End If at the end (before End Sub)

    What is the error message you're getting?

  5. #5
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: (CODE) Help me on this VBA code. Error msg

    Hi, zhengzhi8806,

    please take a minute to think about the thread title.

    Sub Final1()
    
    Dim iRow As Integer
    Dim iCol As Integer
    Dim temp As Integer
    
    
    For iRow = 5 To 6
      If iRow = 20 Or iRow = 36 Then
        'DO NOTHING
      Else
        For iCol = 6 To 8
          temp = Sheets("Scenarios").Cells(3, iCol).Value
          Sheets("Plan Attributes").Range("B4").Value = Sheets("Scenarios").Cells(3, iCol).Value
          Sheets("Plan Attributes").Range("C62:HJ74").Copy
          Sheets("Results").Select
          With Cells(2, temp + 2)
            If temp = 1 Then
              .PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
                 :=False, Transpose:=False
            Else
              .PasteSpecial Paste:=xlPasteValues, Operation:=xlAdd, SkipBlanks _
                 :=False, Transpose:=False
            End If
          End With
        Next iCol
      End If
    Next iRow
    
    
    End Sub
    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  6. #6
    Registered User
    Join Date
    04-15-2013
    Location
    Toronto
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: (CODE) Help me on this VBA code. Error msg

    the error msg is block if without end if.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Getting Error 1004 Object or Application Defined Error - Code to rearrange data
    By BlazzedTroll in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 06-10-2013, 12:10 PM
  2. [SOLVED] IF Exists or on Error Then - Skip Code- How to write code?
    By Jack7774 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-22-2013, 06:45 PM
  3. [SOLVED] Range error in code, runs alone but not inside my full program, giving runtime error 1004
    By charizzardd in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-23-2012, 03:34 PM
  4. Protect/Unprotect code causing out of range error in code
    By Petrolcb41 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-02-2010, 02:34 PM
  5. Error 424 Object Required Error when Using AddItem to ListBox Generated in Code
    By jclark419 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-01-2010, 12:47 PM

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