Adding Two Columns in Excel using a Macro

 First to go Visual Basic Editor follow these steps

1) Press ALT+F11

2)Insert->Module

3)In the Module paste this code

Sub s()
'Declaring variables

Dim i As Integer
Dim j As Integer

For i = 1 To 100
'Looping from 1 to 100 Columns
'Adding contents in Column1 and Column 2
a = Sheet1.Cells(i, 1) + Sheet1.Cells(i, 2)
'Storing the Result in Column 3

Sheet1.Cells(i, 3) = a
End Sub

This code works only when data is stored in first column and second column,you can modify this code to add any two columns ,to modify it just do like this

Sheet1.Cells(i,Columnnumber)

In the column number you should put your own column numberand sameis thecase with row number also

To change the row number just replace i=1 in the for Loop with your own number

This entry was posted on Wednesday, January 21st, 2009 at 12:53 am and is filed under Others. You can follow any responses to this entry through the RSS 2.0 feed. You can skip to the end and leave a response. Pinging is currently not allowed.

Post a Comment