Results 1 to 3 of 3

Thread: [RESOLVED] Create new column based on two other columns

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2011
    Posts
    6

    Resolved [RESOLVED] Create new column based on two other columns

    Hello,

    I need to create a column with vba, it should be the last one in the worksheet.
    In each cell of the column, the value should be the sum of 2 other cells from 2 different columns.
    So i think i need a function that loops through the two columns, sums up the values and places that value in the same row in the new column, right?
    I need some help with the syntax..

    I am a beginner in vba, so i'm sorry if I made any mistakes in my post!

    Thank you!

  2. #2
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: Create new column based on two other columns

    Welcome to VBForums

    put that in a module.
    Code:
    Public Sub SummValues()
    'Summ the values of two adjacent cells in each row and put the result into the next column
    Dim MyRow As Long
    'change the Sheet by number or name at your needs!
    With ThisWorkbook.Sheets(1)
        For Each c In .Range("A:A")
            MyRow = c.Row
            'The result will be put in Column 3 (i.e "C") change at your needs!
            .Cells(MyRow, 3).Value = .Cells(MyRow, 29).Value + c.Value
        Next c
    End With
    End Sub
    You will notice that this code runs for some seconds. that is because there is no check when the end. You could for example end when the first empty cell is found in column A (or whichever you need).
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  3. #3

    Thread Starter
    New Member
    Join Date
    Nov 2011
    Posts
    6

    Re: Create new column based on two other columns

    That did it!
    Thank you so much!

Posting Permissions

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



Click Here to Expand Forum to Full Width