People take a survey and their responses end up in one row in an Excel spreadsheet. People take multiple surveys, so their responses are spread throughout multiple worksheets. These people have IDs they use before every survey.
I want to loop through rows in each worksheet and copy select cells from the row with a particular person's survey responses. The assumption is the person pulling responses together into one spreadsheet knows the ID.
What I have so far is this:
Sub CreateSPSSFeed()
Dim StudentID As String ' (StudentID is a unique identifier)
Dim Tool As Worksheet ' (this is the worksheet I'm pulling data into)
Dim Survey1 As Worksheet ' (this is the sheet I'm pulling data from)
Dim i As Integer ' (loop counter)
Tool = ActiveWorkbook.Sheets("ToolSheet")
Survey1 = ActiveWorkbook.Sheets("Survey1Sheet")
' (This is how the loop knows what to look for)
StudentID = Worksheet("ToolSheet").Range("A2").Value
ActiveWorksheet("Survey1").Select ' (This loop start with the Survey1 sheet)
For i = 1 to Rows.Count ' (Got an overflow error here)
If Cells (i, 1).Value = StudentID Then
'!Unsure what to do here-- need the rest of the row
' with the matching StudentID copied and pasted
' to a specific row in ToolSheet, let's say starting at G7!
End If
Next i
End Sub
I definitely don't intend for anyone to do the work for me. I've tried researching concepts and language here and haven't had a lot of luck combining loops with moving across sheets.
This one's not good, but may get you going:
Try this:
Run this code only from sheet where you pooling data into "Tool". Now you have nested loop for rows in loop for sheets. PS: no need to copy entire row, just range with value, to avoid errors.
This will check rows 1:500 (can easily change to entire column or different range) in all sheets in the workbook that starts with 'Survey' and paste to the tool sheet. Ensure you have enough space between student id's on the toolsheet to paste all possible occurrences.
The FIND method is from here: https://msdn.microsoft.com/en-us/library/office/ff839746.aspx
Edit: I've added more comments and extra code as realised the first section would always find the Student ID that is placed in cell A2.