[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..:D
I am a beginner in vba, so i'm sorry if I made any mistakes in my post!
Thank you! :)
Re: Create new column based on two other columns
Welcome to VBForums :wave:
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).
Re: Create new column based on two other columns
That did it!
Thank you so much!