Hello,
I am newly registered but not new to search in this forum for new approaches of better structuring my vba code. Still, now I am facing a wall with which I think the solution would be a nested loop (but I might be mistaken).
Document: 1 workbook, 13 sheets (the first is called "sheet1", the last one is called "compilation", in between sheets named "1" till "11")
Datasheet: "sheet1", data structured in columns A (question with number 01 till 11), columns B (contributors' name alphabetically ordered), column C (answer). The number of rows is the same in between the 3 columns.
What I have: a VBA code that runs a loop that will autofilter through the questions numbers and copy the filtered results to a worksheet.
What I would like to do: the above code successively autofilter results from question 01 to 11 and copy-paste the results into another sheet that remains worksheet ("1"). Is it possible to modify this code to copy filtered results from question 1 to sheet "1", from question 2 to sheet "2" etc. till question 11 to sheet "11"? In the affirmative, how would you do it?
Many thanks in advance for your help!
I am newly registered but not new to search in this forum for new approaches of better structuring my vba code. Still, now I am facing a wall with which I think the solution would be a nested loop (but I might be mistaken).
Document: 1 workbook, 13 sheets (the first is called "sheet1", the last one is called "compilation", in between sheets named "1" till "11")
Datasheet: "sheet1", data structured in columns A (question with number 01 till 11), columns B (contributors' name alphabetically ordered), column C (answer). The number of rows is the same in between the 3 columns.
What I have: a VBA code that runs a loop that will autofilter through the questions numbers and copy the filtered results to a worksheet.
Code:
Sub fun()
Dim o_cell As Range
Dim wkD As Worksheet
Dim LR As Variant
Dim i As Integer
'source data
Set o_cell = ThisWorkbook.Worksheets("<wbr>Sheet1").Range("A1").<wbr>CurrentRegion
'Destination sheet that is set
Set wkD = ThisWorkbook.Worksheets("1")
'set Lastrow for column A. Columns A,B & C have the same number of rows
LR = o_cell.Cells(Rows.Count, 1).End(xlUp).Row
For i = 1 To 11
o_cell.AutoFilter field:=1, Criteria1:="=" & i & ".*", Operator:=xlAnd
Range("A1:C" & LR).Copy
wkD.Range("A1").PasteSpecial Paste:=xlPasteValues
o_cell.AutoFilter
Next i
End Sub
What I would like to do: the above code successively autofilter results from question 01 to 11 and copy-paste the results into another sheet that remains worksheet ("1"). Is it possible to modify this code to copy filtered results from question 1 to sheet "1", from question 2 to sheet "2" etc. till question 11 to sheet "11"? In the affirmative, how would you do it?
Many thanks in advance for your help!