Solved

extract usable data from a google docs spreadsheet

Posted on 2013-12-12
9
443 Views
Last Modified: 2013-12-31
Hi folks,

I am collecting registration information for a conference using a Formstack form, which is dumping the collected data into a Google spreadsheet. People are registering for breakout sessions, of which there are five, with twelve different streams available for each session. For each session they are asked to list their preferred streams, using 1, 2, 3.

What I need help with is (and maybe I'm just too tired at the moment to process it clearly!) that I need to:
keep track of the total number of first preferences for each stream as registrations come in (I can't just use COUNTIF in a row in Google spreadsheets as the new registrations from Formstack are always added to the very bottom of the spreadsheet)
create lists of the registrants in each stream (that I can ultimately print out and check people off against as they arrive)
create a list of streams each registrant has registered for (again ideally printable by individual registrant, to be provided to each for reference)

I'm open to any ideas on the best way to go about this, without having to pay for extra software. I have access to Excel, but not MS Access - happy to use the DB part of OpenOffice if that's the best way forward.

Thanks in advance for your suggestions.
0
Comment
Question by:stretchr
  • 5
  • 4
9 Comments
 
LVL 11

Expert Comment

by:Angelp1ay
ID: 39715966
Hi stretchr

Could you post your spreadsheet or an example so we can see the structure?
0
 

Author Comment

by:stretchr
ID: 39716046
Here's a screenshot of part of the spreadsheet, annotated. If it's not straightforward what you're seeing, let me know.
SessionsSpreadsheetStructure.png
0
 
LVL 11

Expert Comment

by:Angelp1ay
ID: 39716521
Solution

Please see attached example :)

Here is the code for the macros (hopefully it's easy enough to follow). The second is almost identical to the first, just looping row then col instead of col then row.
Public Sub PrintPerStream()
    
    ' Find the data
    Dim sh As Excel.Worksheet
    Set sh = Worksheets("Raw Data")
    
    Dim lastCol, lastRow As Integer
    lastCol = sh.UsedRange.Columns.Count
    lastRow = sh.UsedRange.Rows.Count
    
    ' Create word app and doc
    Dim wordApp As Word.Application
    Dim wordDoc As Word.Document
    
    Set wordApp = CreateObject("Word.Application")
    Set wordDoc = wordApp.Documents.Add
    wordApp.Visible = True

    ' Write to word
    Dim col, row, cCount As Integer, sel
    Set sel = wordApp.Selection
    
    For col = 5 To lastCol
        ' Stream name
        sel.Style = wordDoc.Styles("Heading 3")
        sel.TypeText sh.Cells(1, col).Value & vbCrLf
        
        cCount = 0
        For row = 2 To lastRow
            ' Registrant name
            If sh.Cells(row, col).Value = 1 Then
                sel.Style = wordDoc.Styles("Normal")
                sel.TypeText sh.Cells(row, 3).Value & vbCrLf
                cCount = cCount + 1
            End If
        Next
        If cCount = 0 Then
            sel.Style = wordDoc.Styles("Normal")
            sel.TypeText "No registrants" & vbCrLf
        End If
    Next
End Sub

Open in new window

Public Sub PrintPerRegistrant()
    
    ' Find the data
    Dim sh As Excel.Worksheet
    Set sh = Worksheets("Raw Data")
    
    Dim lastCol, lastRow As Integer
    lastCol = sh.UsedRange.Columns.Count
    lastRow = sh.UsedRange.Rows.Count
    
    ' Create word app and doc
    Dim wordApp As Word.Application
    Dim wordDoc As Word.Document
    
    Set wordApp = CreateObject("Word.Application")
    Set wordDoc = wordApp.Documents.Add
    wordApp.Visible = True

    ' Write to word
    Dim col, row, rCount As Integer, sel
    Set sel = wordApp.Selection
    
    For row = 2 To lastRow
        ' Registrant name
        sel.Style = wordDoc.Styles("Heading 3")
        sel.TypeText sh.Cells(row, 3).Value & vbCrLf
    
        rCount = 0
        For col = 5 To lastCol
            ' Stream name
            If sh.Cells(row, col).Value = 1 Then
                sel.Style = wordDoc.Styles("Normal")
                sel.TypeText sh.Cells(1, col).Value & vbCrLf
                rCount = rCount + 1
            End If
        Next
        If rCount = 0 Then
            sel.Style = wordDoc.Styles("Normal")
            sel.TypeText "No registrations" & vbCrLf
        End If
    Next
End Sub

Open in new window


Explanation

keep track of the total number of first preferences for each stream as registrations come in (I can't just use COUNTIF in a row in Google spreadsheets as the new registrations from Formstack are always added to the very bottom of the spreadsheet)

I'm not sure why you say this, and perhaps I've misunderstood. Check the second sheet of the example where I just COUNTIF on the entire column (which should catch anything anywhere including the bottom).

create lists of the registrants in each stream (that I can ultimately print out and check people off against as they arrive)

On the second form hit the "Print per Stream" button. It will dump the list out to Word.

create a list of streams each registrant has registered for (again ideally printable by individual registrant, to be provided to each for reference)

On the second form hit the "Print per Registrant" button. It will dump the list out to Word.
Streams.xlsm
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 

Author Comment

by:stretchr
ID: 39718017
You're right, I could put the COUNTIF in another sheet in the workbook.

Are these macros for Excel? That's ok but I will only be able to use them right at the end of the registration process when I dump the spreadsheet out of Google into Excel.

I'll be away for a few days now, so any more comments I'll respond to when I'm back.
0
 

Author Comment

by:stretchr
ID: 39743389
Hello,

I'm back on deck now, and have copied your code over into my own spreadsheet. I am having a problem where when I try to run the macro, I receive an error on the line "Dim wordApp as Word.application" which says "Compile error: User-defined type not defined". It's weird, because your sample sheet works fine.

I have one further thing, which if you could tell me how to modify your code, would be great. I've had to separate the registrant name field into first name and last name, so as I can sort by last name. I'm just not quite sure how to implement that additional step in your macro code.
0
 
LVL 11

Assisted Solution

by:Angelp1ay
Angelp1ay earned 450 total points
ID: 39743543
Sorry, should have mentioned that. You need to add Word to the references!
Adding a ReferenceWord Object Library
0
 

Author Comment

by:stretchr
ID: 39744527
Many thanks, that was just what I was looking for.

Now, just for my last point in my previous comment - I have had to split the name into two cells, first and last. What adjustments do I need to make in the macro to make it export the first and last names separately into Word, with a space between? I have figured out how to adjust the column references, but the rest escapes me. Can you show me the solution to that?
0
 
LVL 11

Accepted Solution

by:
Angelp1ay earned 450 total points
ID: 39747845
You just need to update the block of code marked "registrant name" in each macro.

Assuming you now have first name in col 3 and last name in col 4:
            ' Registrant name
            If sh.Cells(row, col).Value = 1 Then
                sel.Style = wordDoc.Styles("Normal")
                sel.TypeText sh.Cells(row, 3).Value & " " & sh.Cells(row, 4).Value & vbCrLf
                cCount = cCount + 1
            End If

Open in new window

The important bit is the selection type text command (sel.TypeText) which dumps out to word. The updated example above means write out:
- value at current row, 3rd column (first name)
- space
- value at current row, 4th column (second name)
- line break

Note: If you've also shifted the rest of the columns you'll have to update the loop counter for the column too e.g.
For col = 6 To lastCol

Open in new window


Updated macros in full:
Public Sub PrintPerStream()
    
    ' Find the data
    Dim sh As Excel.Worksheet
    Set sh = Worksheets("Raw Data")
    
    Dim lastCol, lastRow As Integer
    lastCol = sh.UsedRange.Columns.Count
    lastRow = sh.UsedRange.Rows.Count
    
    ' Create word app and doc
    Dim wordApp As Word.Application
    Dim wordDoc As Word.Document
    
    Set wordApp = CreateObject("Word.Application")
    Set wordDoc = wordApp.Documents.Add
    wordApp.Visible = True

    ' Write to word
    Dim col, row, cCount As Integer, sel
    Set sel = wordApp.Selection
    
    For col = 6 To lastCol
        ' Stream name
        sel.Style = wordDoc.Styles("Heading 3")
        sel.TypeText sh.Cells(1, col).Value & vbCrLf
        
        cCount = 0
        For row = 2 To lastRow
            ' Registrant name
            If sh.Cells(row, col).Value = 1 Then
                sel.Style = wordDoc.Styles("Normal")
                sel.TypeText sh.Cells(row, 3).Value & " " & sh.Cells(row, 4).Value & vbCrLf
                cCount = cCount + 1
            End If
        Next
        If cCount = 0 Then
            sel.Style = wordDoc.Styles("Normal")
            sel.TypeText "No registrants" & vbCrLf
        End If
    Next
End Sub

Open in new window


Public Sub PrintPerRegistrant()
    
    ' Find the data
    Dim sh As Excel.Worksheet
    Set sh = Worksheets("Raw Data")
    
    Dim lastCol, lastRow As Integer
    lastCol = sh.UsedRange.Columns.Count
    lastRow = sh.UsedRange.Rows.Count
    
    ' Create word app and doc
    Dim wordApp As Word.Application
    Dim wordDoc As Word.Document
    
    Set wordApp = CreateObject("Word.Application")
    Set wordDoc = wordApp.Documents.Add
    wordApp.Visible = True

    ' Write to word
    Dim col, row, rCount As Integer, sel
    Set sel = wordApp.Selection
    
    For row = 2 To lastRow
        ' Registrant name
        sel.Style = wordDoc.Styles("Heading 3")
        sel.TypeText sh.Cells(row, 3).Value & " " & sh.Cells(row, 4).Value & vbCrLf
    
        rCount = 0
        For col = 6 To lastCol
            ' Stream name
            If sh.Cells(row, col).Value = 1 Then
                sel.Style = wordDoc.Styles("Normal")
                sel.TypeText sh.Cells(1, col).Value & vbCrLf
                rCount = rCount + 1
            End If
        Next
        If rCount = 0 Then
            sel.Style = wordDoc.Styles("Normal")
            sel.TypeText "No registrations" & vbCrLf
        End If
    Next
End Sub

Open in new window

0
 

Author Comment

by:stretchr
ID: 39748004
Ahh, thankyou very much, I follow all that now!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
Viewers will learn what comprises a theme in Excel 2013, as well as how to customize them.
Viewers will learn various types of data validation for different data types in Excel 2013.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question