Visual Basic

It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration.

Edsger Dijkstra

Yesterday I had to type in 188 Excel spreadsheets some numbers. I’ve never learnt Visual Basic, thankfully I never had to teach it also 🙂 but it was something useful to try out for the specific task. That’s a stripped version of what came up:

Sub wrSheets()
Dim sheetName
For i = 2 To 189
    stri = CStr(i)
    sheetName = Range("Q" & stri).Value
    val = Range("H" & stri).Value
    With Worksheets(sheetName)
        .Range("Q38") = val
    End With
Next i

End Sub

With VBA, Excel did the tedious task in one second. That was awesome. Of course I went online for all these things. The error messages were more cryptic than expected and, why .Range instead of just Range? Anyway it did my job so…


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s