Sunday, February 22, 2009

My First Excel Macro

Nothing to write home to mom about, but I have gone from programming in C++ to Java to VBA. My first VBA script does very little but it saved me a lot of time

Dim x As Integer
x = 1
For Each oRow In Sheet1.Range("A:A")
For Each nRow In Sheet2.Range("A1:A244")
If (oRow = nRow) Then
Sheet3.Cells(x, 1) = oRow
x = x + 1
End If
Next nRow
Next oRow
Dim row
End Sub

Basically checks if the the elements from Range A:A (i.e. all the elements in the column) in Sheet 1 were repeated in A2:A244 in Sheet 2. I could have exported the sheet into a csv file and written a perl script or something in java to do it. But it's always fun to experiment with a new language.

Labels: ,