I tried searching meta if this has already been covered in the past but couldn't find it.

Is there a way I can see the current status of the voting results in a table? Something like this at a click of a button?

enter image description here

I can write a macro for this and it will take me 15 mins for that but wanted to be sure that I am not re-inventing the wheel.


User Jeremy Banks has created script that can be used in the JavaScript Console of your browser it is located on github. He posted this in the Election Chat Room- here is the transcript

@MadaraUchiha Copy this script into your JavaScript console on the election page: gist.github.com/jeremybanks/2913432/raw/…

enter image description here

  • 2
    Thanks bluefeet. I am kind of novice and am sure many of us might be when it comes to using the JavaScript Console of the browser. Can you shed more light on it? I mean what is it and how do I use it? Thanks for taking the time out to reply. :) Feb 18 '14 at 11:37
  • 1
    @SiddharthRout Depending on your browser, you should have a tools option with Javascript Console. For example, I use Chrome if I go to Tools, there is a selection for the console. You can paste the script into the window.
    – Taryn
    Feb 18 '14 at 11:44
  • Thank you. Let me test it. Feb 18 '14 at 11:44
  • + 1 I couldn't figure it out so I wrote a small macro instead. i am sure the script that you mentioned works :) Feb 18 '14 at 11:50
  • For anyone interested, I've made a small change so it includes your own vote at the end.
    – Stijn
    Feb 18 '14 at 11:50

Edit History

Version 2 Updated at the end of the post.

Ok an alternative.

I created a small macro. You can download the file from THIS link


  1. You should have MS Excel 2007+ with macros enabled.
  2. Ensure you have IE and you are logged in with "Remember the password" option. After that you may close the browser.


enter image description here


People who are not able to visit that site can create a button in the worksheet and use this code.

Private Sub CommandButton1_Click()
    Dim htmlDoc As HTMLDocument, htmlBod As HTMLBody
    Dim tr As HTMLTableRow, span As HTMLSpanElement
    Dim ws As Worksheet, i As Integer, lastRow As Integer
    Dim IE As Object
    Dim data() As String

    ReDim data(2, 500) As String

    Set IE = CreateObject("InternetExplorer.Application")
    IE.navigate "http://stackoverflow.com/election"

    '~~> One may set it to false
    IE.Visible = True

    Do While IE.Busy And IE.readyState <> 4: DoEvents: Loop

    Set htmlDoc = New HTMLDocument
    Set htmlBod = htmlDoc.body

    htmlBod.innerHTML = IE.document.body.innerHTML
    htmlBod.innerHTML = htmlDoc.getElementById("mainbar").outerHTML

    Set IE = Nothing

    lastRow = 1

    For Each tr In htmlBod.getElementsByTagName("TR")
        If tr.ID Like "post-########" Then
            If tr.getElementsByClassName("user-details").Length > 1 Then
                data(1, lastRow) = tr.getElementsByClassName("user-details")(1).Children(0).innerText
                For Each span In tr.getElementsByTagName("span")
                    If span.className = "vote-count-post" Then
                        data(2, lastRow) = span.innerText
                        Exit For
                    End If
                lastRow = lastRow + 1
            End If
        End If

    ReDim Preserve data(2, lastRow) As String

    Set ws = ActiveSheet


    For i = 1 To lastRow
        ws.Cells(i, 1) = data(1, i)
        ws.Cells(i, 2) = data(2, i)

    ws.Columns("A:B").Sort Key1:=ws.Range("B1"), Order1:=xlDescending, Header:=xlNo, _
    OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
End Sub

Do set a reference to the respective libraries as shown in the pic below.

enter image description here

EDIT - Version 2

This will let you do a historic analysis between two candidates. Please select the names from the drop downs in the YELLOW Cell and click on Compare

Also you can only have 10 points of data in one table. After 10 points, you will have to clear the table by pressing Clear and then start all over again. To populate the table, click on Refresh

enter image description here

File can be downloaded from HERE

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .