Need Help with VBA Code

Megha1484

New Member
Joined
Nov 10, 2018
Messages
17
Hi,
I have been struggling with this VBA code for quite some time now and would appreciate any help with it. I have attached a sample spreadsheet I am working with. First sheet shows the raw data that comes from the SharePoint and second sheet shows the report I am trying to build form the raw data. Goal is to search for each question (starts at col C) and look for any “No – Correction Needed” and “No – Correction Not Needed” words and display the corresponding “ID”, “Name”, “Notes” associated with the question and “correction made”. I don’t want any “yes” or NA in the report only “Nos*”.
I have filled question “TND” as an example. So, when I run the code it should go through the entire col look for Nos and fill out rest of fields that comes from raw data. Here is the code I am trying to work with.
There are couple of issues with it. First, every time I will run the code it will start from scratch instead of picking up the row where it left off last. This could be an issue overtime when data starts building up.
Second, I am going to have to write the same code 32 times one for each question, which is OK as long as I can make this code work.
Third, I think its not recognizing the new report location where I am trying to build the report.


Sorry, I could not find a way to attach to Excel workbook so copied the sheets at the bottom of the email. First table is Rawdata and second table is Report. Thanks in advance!



Sub Report ()
'builds the report line by line based on iterative check of criteria

'clear old report data
Sheets ("Report").Select
Range("3:3").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Delete Shift:=xlUp

'set up for report build
Range("Report[Question ID]").Select


'iteratively search for selected criteria for Q1

Dim Q1Column As Range
Dim q1answer As Range
Dim q1current As Range


Set Q1Column = Sheets("Rawdata").Range("Table_Rawdata[Memo]")
For Each q1answer In Q1Column.Cells
If q1answer.Value Like "No*" Then
Set q1current = Range(Cells(ActiveCell))
Range("Report[@[Question ID]]").Select
Set ActiveCell.Value = "Q.1"
ActiveCell.Offset(0, 1).Select
Set ActiveCell.Value = "TD"
ActiveCell.Offset(0, 1).Select
Set ActiveCell.Value = "Deatiled Question Description"
ActiveCell.Offset(0, 1).Select
Set ActiveCell.Value = "Memo"
ActiveCell.Offset(0, 1).Select
Set ActiveCell.Value = Cells(q1current.Row, Range("Table_Rawdata[@[Name]]").Column)
ActiveCell.Offset(0, 1).Select
Set ActiveCell.Value = q1answer.Value
ActiveCell.Offset(0, 1).Select
Set ActiveCell.Value = Cells(q1current.Row, Range("Table_Rawdata[@[CorrectionsMade]]").Column)
ActiveCell.Offset(0, 1).Select
Set ActiveCell.Value = Cells(q1current.Row, Range("Table_Rawdata[@[MemoNotes]]").Column)
ActiveCell.Offset(0, 1).Select
Set ActiveCell.Value = Cells(q1current.Row, Range("Table_Rawdata[@[ID]]").Column)

Else
End If
Next q1answer

'Next datum - copy code for the next question...
End Sub


RawData(Sheet1)

IDNameMemoTNDSTWDecAccConProCoDBegDatDurationCPContributionFIMFMBPRpayOffAccReAccReErrAmtErrAmtICDmetStatusResAccuteBenaccuPETComAAuCplanDMWUSUIOSalPrePdatOUPYAmanClInterWrkstBupWkstLwaiversReviewCCCompTimExtRDMDReview DateCorrectionsMadeMemoNOtesTNDNotesSTWNotesDecAccNotesConProNotesCoDNotesBegDatNotesDurationNotesCPNotesContributionNotesFIMFNotesMBPNotesRpayNotesOffAccNotesReAccNotesReErrNotesAmtNotesErrAmtNotesICNotesDmetNotesStatusNotesResAccuteNotesBenaccuNotesPETNotesComANotesAuNotesCplanNotesDMWUNotesSUIONotesSalPreNotesPdatNotesItem
4567678MHYesNo - Correction NeededN/ANo - Correction NeededNo - Correction NeededNo - Correction Not NeededYesYesN/AYesYesN/AN/ANo - Correction Needed1000000200000YesYesNo - Correction NeededN/AYesYesYesN/AYesN/ANo - Correction Not NeededYesYesN/ANo - Correction NeededNo - Correction Not NeededNo - Correction Not Needed1/30/2019YesdgddItem
67890SGYesNo - Correction Not NeededYesNo - Correction Not NeededNo - Correction Not NeededNo - Correction NeededN/AN/AYesYesYesYesN/ANo - Correction Needed45666750000010000YesN/AYesN/AYesNo - Correction NeededYesYesN/AYesYesNo - Correction Not NeededYesYesYesYesYesN/ANo - Correction Not NeededNo - Correction NeededNo - Correction Not Needed1/16/2019Nofgfgdgdgd​bzdbxb​fbxb​xb​​eytsghsfth​fgfbxbfbxbb​bbxb​xfbxb​​fxgxfxhfbxxfb​Item
45678CLYesNo - Correction NeededNo - Correction NeededNo - Correction Not NeededN/ANo - Correction NeededYesYesYesYesYesN/AYesNo - Correction Needed1500000200000YesYesN/ANo - Correction NeededNo - Correction Not NeededYesYesYesYesN/ANo - Correction NeededYesYesYesNo - Correction NeededNo - Correction Not NeededNo - Correction Not Needed2/13/2019YescvddfgItem
45678DGYesYesYesNo - Correction Not NeededNo - Correction Not NeededNo - Correction NeededN/AN/AYesYesYesYesN/AYes70000050000YesYesNo - Correction Not NeededNo - Correction Not NeededNo - Correction NeededYesYesYesYesYesNo - Correction Not NeededYesYesN/AYesYesYes8/14/2019NocxvxcvxcItem
45678DLYes
No - Correction Not NeededN/ANo - Correction Not NeededNo - Correction Not NeededNo - Correction NeededYesYesYesYesYesYesN/ANo - Correction Not Needed75000010000N/AYesNo - Correction NeededNo - Correction NeededNo - Correction Not NeededYesYesYesYesYesNo - Correction NeededYesYesYesNo - Correction NeededYesYes4/16/2020Yes gdfhhItem
45678GSYesNo - Correction NeededN/ANo - Correction Not NeededNo - Correction NeededNo - Correction NeededYesYesYesYesYesYesYesNo - Correction Needed3000002000N/AYesNo - Correction Not NeededNo - Correction Not NeededNo - Correction NeededYesYesN/AYesYesN/AYesYesYesNo - Correction NeededYesYes9/24/2020NogdfggItem
56789MBYesNo - Correction NeededN/ANo - Correction Not NeededN/ANo - Correction NeededYesN/AYesNo - Correction NeededYesNo - Correction NeededYes60000020000No - Correction Not NeededNo - Correction Not NeededNo - Correction Not NeededNo - Correction NeededYesYesYesNo - Correction NeededNo - Correction NeededNo - Correction NeededNo - Correction Not NeededYesNo - Correction Not NeededN/AYesNo - Correction NeededNo - Correction Not Needed2/4/2021NosdgdsgsdItem
234567CLYesYesNo - Correction Not NeededYesNo - Correction NeededN/AN/ANo - Correction NeededNo - Correction NeededNo - Correction Not NeededYesNo - Correction NeededNo - Correction Not NeededYes10000005000060000YesYesNo - Correction Not NeededNo - Correction Not NeededNo - Correction NeededYesN/AYesYesNo - Correction NeededNo - Correction NeededYesNo - Correction Not NeededN/AYesNo - Correction Not NeededYesNo - Correction NeededNo - Correction Not Needed1/15/2019Nosdgsdg​comments​Comment​Comment
​Comments​Comments​comments​comments​comments​COmment​comments​comments​Comments​CommentsItem
692877NBYesNo - Correction Not NeededNo - Correction NeededN/AYesNo - Correction NeededYesYesYesN/AYesN/AN/A957.19N/AN/AN/AYesN/AYesYesN/AN/AN/AN/AN/AN/AN/AN/AN/AN/A1/21/2019Nosdgsdgs​date corrected to reflect earlier onseti:0#.w|sic\kspierinncm consult neededItem
00325698TG1/15/2019NoerteryItem
693008NBN/AN/AN/AYesN/ANo - Correction NeededN/AN/AN/AN/ANo - Correction NeededN/AN/A1000N/ANo - Correction NeededN/AN/AN/AN/AN/AN/AYesN/ANo - Correction NeededYesYesN/ANo - Correction NeededN/ANo - Correction Not Needed1/23/2019Noeryery​disability date should be 10.1Item
00323333TG
1/8/2019NoeryeryItem
<colgroup><col width="65" style="width: 49pt; mso-width-source: userset; mso-width-alt: 2304;"> <col width="106" style="width: 80pt; mso-width-source: userset; mso-width-alt: 3783;"> <col width="101" style="width: 76pt; mso-width-source: userset; mso-width-alt: 3584;"> <col width="175" style="width: 131pt; mso-width-source: userset; mso-width-alt: 6229;"> <col width="149" style="width: 112pt; mso-width-source: userset; mso-width-alt: 5290;"> <col width="175" style="width: 131pt; mso-width-source: userset; mso-width-alt: 6229;" span="3"> <col width="91" style="width: 68pt; mso-width-source: userset; mso-width-alt: 3242;" span="2"> <col width="149" style="width: 112pt; mso-width-source: userset; mso-width-alt: 5290;" span="2"> <col width="175" style="width: 131pt; mso-width-source: userset; mso-width-alt: 6229;"> <col width="149" style="width: 112pt; mso-width-source: userset; mso-width-alt: 5290;" span="2"> <col width="175" style="width: 131pt; mso-width-source: userset; mso-width-alt: 6229;" span="2"> <col width="83" style="width: 62pt; mso-width-source: userset; mso-width-alt: 2958;"> <col width="73" style="width: 55pt; mso-width-source: userset; mso-width-alt: 2588;"> <col width="63" style="width: 47pt; mso-width-source: userset; mso-width-alt: 2247;"> <col width="175" style="width: 131pt; mso-width-source: userset; mso-width-alt: 6229;" span="6"> <col width="98" style="width: 74pt; mso-width-source: userset; mso-width-alt: 3498;"> <col width="62" style="width: 46pt; mso-width-source: userset; mso-width-alt: 2190;"> <col width="149" style="width: 112pt; mso-width-source: userset; mso-width-alt: 5290;" span="3"> <col width="175" style="width: 131pt; mso-width-source: userset; mso-width-alt: 6229;"> <col width="58" style="width: 44pt; mso-width-source: userset; mso-width-alt: 2076;"> <col width="175" style="width: 131pt; mso-width-source: userset; mso-width-alt: 6229;"> <col width="72" style="width: 54pt; mso-width-source: userset; mso-width-alt: 2560;"> <col width="90" style="width: 67pt; mso-width-source: userset; mso-width-alt: 3185;"> <col width="121" style="width: 91pt; mso-width-source: userset; mso-width-alt: 4295;"> <col width="110" style="width: 82pt; mso-width-source: userset; mso-width-alt: 3896;"> <col width="175" style="width: 131pt; mso-width-source: userset; mso-width-alt: 6229;"> <col width="72" style="width: 54pt; mso-width-source: userset; mso-width-alt: 2560;"> <col width="114" style="width: 85pt; mso-width-source: userset; mso-width-alt: 4039;"> <col width="175" style="width: 131pt; mso-width-source: userset; mso-width-alt: 6229;" span="3"> <col width="95" style="width: 71pt; mso-width-source: userset; mso-width-alt: 3384;"> <col width="125" style="width: 94pt; mso-width-source: userset; mso-width-alt: 4437;"> <col width="98" style="width: 73pt; mso-width-source: userset; mso-width-alt: 3470;"> <col width="128" style="width: 96pt; mso-width-source: userset; mso-width-alt: 4551;" span="2"> <col width="101" style="width: 76pt; mso-width-source: userset; mso-width-alt: 3584;"> <col width="134" style="width: 101pt; mso-width-source: userset; mso-width-alt: 4778;"> <col width="150" style="width: 112pt; mso-width-source: userset; mso-width-alt: 5319;"> <col width="109" style="width: 82pt; mso-width-source: userset; mso-width-alt: 3868;"> <col width="155" style="width: 116pt; mso-width-source: userset; mso-width-alt: 5518;"> <col width="232" style="width: 174pt; mso-width-source: userset; mso-width-alt: 8248;"> <col width="146" style="width: 109pt; mso-width-source: userset; mso-width-alt: 5176;"> <col width="133" style="width: 100pt; mso-width-source: userset; mso-width-alt: 4721;"> <col width="91" style="width: 68pt; mso-width-source: userset; mso-width-alt: 3242;"> <col width="133" style="width: 100pt; mso-width-source: userset; mso-width-alt: 4721;"> <col width="143" style="width: 107pt; mso-width-source: userset; mso-width-alt: 5091;"> <col width="137" style="width: 103pt; mso-width-source: userset; mso-width-alt: 4864;"> <col width="134" style="width: 100pt; mso-width-source: userset; mso-width-alt: 4750;"> <col width="164" style="width: 123pt; mso-width-source: userset; mso-width-alt: 5831;"> <col width="138" style="width: 104pt; mso-width-source: userset; mso-width-alt: 4920;"> <col width="173" style="width: 130pt; mso-width-source: userset; mso-width-alt: 6144;"> <col width="169" style="width: 127pt; mso-width-source: userset; mso-width-alt: 6001;"> <col width="94" style="width: 71pt; mso-width-source: userset; mso-width-alt: 3356;"> <col width="118" style="width: 89pt; mso-width-source: userset; mso-width-alt: 4209;"> <col width="143" style="width: 107pt; mso-width-source: userset; mso-width-alt: 5091;"> <col width="152" style="width: 114pt; mso-width-source: userset; mso-width-alt: 5404;"> <col width="102" style="width: 76pt; mso-width-source: userset; mso-width-alt: 3612;"> <col width="162" style="width: 121pt; mso-width-source: userset; mso-width-alt: 5745;"> <col width="90" style="width: 68pt; mso-width-source: userset; mso-width-alt: 3214;"> <col width="134" style="width: 101pt; mso-width-source: userset; mso-width-alt: 4778;"> <col width="126" style="width: 94pt; mso-width-source: userset; mso-width-alt: 4465;"> <col width="145" style="width: 109pt; mso-width-source: userset; mso-width-alt: 5148;"> <col width="132" style="width: 99pt; mso-width-source: userset; mso-width-alt: 4693;"> <col width="66" style="width: 49pt; mso-width-source: userset; mso-width-alt: 2332;"> <tbody> </tbody>



Report (sheet#2)

PREFILLED FIELDPREFILLED FIELDPREFILLED FIELDPREFILLED FIELDComes from Raw DataComes from Raw DataComes from Raw DataComes from Raw DataComes from Raw Data
Question IDCategoryQUESTIONSlist fieldNameCorrectable/Not CorrectableIDNotesCorrectionMade
Q.2TDDetailed Question DescriptionTNDMHNo - Correction Needed4567678dgddYes
Q.2TDDetailed Question DescriptionTNDSGNo - Correction Not Needed67890fgfgdgdgdNo
Q.2TDDetailed Question DescriptionTNDCLNo - Correction Needed45678cvddfgYes
Q.2TDDetailed Question DescriptionTNDDLNo - Correction Not Needed45678 gdfhhYes
Q.2TDDetailed Question DescriptionTNDGSNo - Correction Needed45678gdfggNo
Q.2TDDetailed Question DescriptionTNDMBNo - Correction Needed56789sdgdsgsdNo
Q.2TDDetailed Question DescriptionTNDNBNo - Correction Not Needed692877sdgsdgsNo
Q.3TDDetailed Question DescriptionSTW
Q.3TDDetailed Question DescriptionSTW
Q.3TDDetailed Question DescriptionSTW
Q.3TDDetailed Question DescriptionSTW
Q.3TDDetailed Question DescriptionSTW
Q.3TDDetailed Question DescriptionSTW
Q.3TDDetailed Question DescriptionSTW
Q.3TDDetailed Question DescriptionSTW
Q.5DADetailed Question DescriptionDecAcc
DADetailed Question DescriptionDecAcc
DADetailed Question DescriptionDecAcc
Q.6DADetailed Question DescriptionConPro
Q.7DADetailed Question DescriptionCoD
Q.8PFADetailed Question DescriptionBegDat
Q.9PFADetailed Question DescriptionDuration
PFADetailed Question DescriptionDuration
Q.10PFADetailed Question DescriptionCP
PFADetailed Question DescriptionCP
Q.12PFADetailed Question DescriptionFIMF
PFADetailed Question DescriptionFIMF
Q.13PFADetailed Question DescriptionMBP
PFADetailed Question DescriptionRpay
Q.14PFADetailed Question DescriptionOffAcc
PFADetailed Question DescriptionOffAcc
Q.15PFADetailed Question DescriptionReAcc
<colgroup><col width="166" style="width: 125pt;" span="2"> <col width="166" style="width: 125pt;" span="7"> <tbody> </tbody>
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Try this for all the questions

Code:
Sub Fill_Report()
    Dim ws1 As Worksheet, ws2 As Worksheet
    Dim answer As Range
    Dim q As Long, j As Long
    
    Application.ScreenUpdating = False
    
    Set ws1 = Sheets("Rawdata")
    Set ws2 = Sheets("Report")
    
    'clear old report data
    ws2.Rows("3:" & Rows.Count).ClearContents
    ws2.ListObjects("Report").Resize Range("$A$2:$I$3")
    
    q = 1   'Initial question number
    j = 3   'Initial row target
    
    'Column C initial question To column AR end question
    For i = Columns("C").Column To Columns("AR").Column
        For Each answer In ws1.Range("Table_Rawdata[" & ws1.Cells(1, i).Value & "]").Cells
            If answer.Value Like "No*" Then
                ws2.Cells(j, "A").Value = "Q." & q                                                      'question ID
                ws2.Cells(j, "B").Value = "Category"                                                    'category
                ws2.Cells(j, "C").Value = "Deatiled Question Description"                               'question
                ws2.Cells(j, "D").Value = ws1.Cells(1, i).Value                                         'list field
                ws2.Cells(j, "E").Value = ws1.Cells(answer.Row, Range("Table_Rawdata[[Name]]").Column)  'name
                ws2.Cells(j, "F").Value = answer.Value                                                  'Correctable/Not Correctable
                ws2.Cells(j, "G").Value = ws1.Cells(answer.Row, Range("Table_Rawdata[[ID]]").Column)    'ID
                ws2.Cells(j, "H").Value = ws1.Cells(answer.Row, Range("Table_Rawdata[[TNDNotes]]").Column)  'Notes
                ws2.Cells(j, "I").Value = ws1.Cells(answer.Row, Range("Table_Rawdata[[CorrectionsMade]]").Column)   'CorrectionMade
                j = j + 1
            End If
        Next
        q = q + 1
    Next
    
    Application.ScreenUpdating = True
    
    MsgBox "End"
End Sub
 
Upvote 0
Thanks for the quick reply, really appreciate your help. I ran the code and it works till ws2.row("3:" & Rows.Count).ClearContents. After that it gives me a "Run time error '9' Subscript out of range err"







Try this for all the questions

Code:
Sub Fill_Report()
    Dim ws1 As Worksheet, ws2 As Worksheet
    Dim answer As Range
    Dim q As Long, j As Long
    
    Application.ScreenUpdating = False
    
    Set ws1 = Sheets("Rawdata")
    Set ws2 = Sheets("Report")
    
    'clear old report data
    ws2.Rows("3:" & Rows.Count).ClearContents
    ws2.ListObjects("Report").Resize Range("$A$2:$I$3")
    
    q = 1   'Initial question number
    j = 3   'Initial row target
    
    'Column C initial question To column AR end question
    For i = Columns("C").Column To Columns("AR").Column
        For Each answer In ws1.Range("Table_Rawdata[" & ws1.Cells(1, i).Value & "]").Cells
            If answer.Value Like "No*" Then
                ws2.Cells(j, "A").Value = "Q." & q                                                      'question ID
                ws2.Cells(j, "B").Value = "Category"                                                    'category
                ws2.Cells(j, "C").Value = "Deatiled Question Description"                               'question
                ws2.Cells(j, "D").Value = ws1.Cells(1, i).Value                                         'list field
                ws2.Cells(j, "E").Value = ws1.Cells(answer.Row, Range("Table_Rawdata[[Name]]").Column)  'name
                ws2.Cells(j, "F").Value = answer.Value                                                  'Correctable/Not Correctable
                ws2.Cells(j, "G").Value = ws1.Cells(answer.Row, Range("Table_Rawdata[[ID]]").Column)    'ID
                ws2.Cells(j, "H").Value = ws1.Cells(answer.Row, Range("Table_Rawdata[[TNDNotes]]").Column)  'Notes
                ws2.Cells(j, "I").Value = ws1.Cells(answer.Row, Range("Table_Rawdata[[CorrectionsMade]]").Column)   'CorrectionMade
                j = j + 1
            End If
        Next
        q = q + 1
    Next
    
    Application.ScreenUpdating = True
    
    MsgBox "End"
End Sub
 
Upvote 0
Remove this line and try again

Code:
ws2.ListObjects("Report").Resize Range("$A$2:$I$3")
 
Upvote 0
sorry, the image did not come through.

Run-time error'1004' Method 'Rang' of Object'_Worksheet' failed on line

For Each answer In ws1.Range("Table_Rawdata[" & ws1.Cells(1, i).Value & "]").Cells
 
Upvote 0
Try this,

Sorry but, I'm trying to guess where your "Table_Rawdata" and "Report" tables are. If you have another problem, You could upload a copy of your file to a free site such as www.box.com or www.dropbox.com. Once you do that, mark it for 'Sharing' and you will be given a link to the file that you can post here. If the workbook contains confidential information, you could replace it with generic data.

Code:
Sub Fill_Report()
    Dim ws1 As Worksheet, ws2 As Worksheet
    Dim answer As Range
    Dim q As Long, j As Long, initial As Long
    
    Application.ScreenUpdating = False
    
    Set ws1 = Sheets("Rawdata")
    Set ws2 = Sheets("Report")
    
    'clear old report data
    ws2.Rows("3:" & Rows.Count).ClearContents
    'ws2.ListObjects("Report").Resize Range("$A$2:$I$3")
    
    q = 1   'Initial question number
    j = 3   'Initial row target
    
    'Column C initial question To column AR end question
    initial = ws1.Range("Table_Rawdata[#All]").Cells(1, 1).Row
    For i = Columns("C").Column To Columns("AR").Column
        For Each answer In ws1.Range("Table_Rawdata[" & ws1.Cells(initial, i).Value & "]").Cells
            If answer.Value Like "No*" Then
                ws2.Cells(j, "A").Value = "Q." & q                                                      'question ID
                ws2.Cells(j, "B").Value = "Category"                                                    'category
                ws2.Cells(j, "C").Value = "Deatiled Question Description"                               'question
                ws2.Cells(j, "D").Value = ws1.Cells(1, i).Value                                         'list field
                ws2.Cells(j, "E").Value = ws1.Cells(answer.Row, Range("Table_Rawdata[[Name]]").Column)  'name
                ws2.Cells(j, "F").Value = answer.Value                                                  'Correctable/Not Correctable
                ws2.Cells(j, "G").Value = ws1.Cells(answer.Row, Range("Table_Rawdata[[ID]]").Column)    'ID
                ws2.Cells(j, "H").Value = ws1.Cells(answer.Row, Range("Table_Rawdata[[TNDNotes]]").Column)  'Notes
                ws2.Cells(j, "I").Value = ws1.Cells(answer.Row, Range("Table_Rawdata[[CorrectionsMade]]").Column)   'CorrectionMade
                j = j + 1
            End If
        Next
        q = q + 1
    Next
    
    Application.ScreenUpdating = True
    
    MsgBox "End"
End Sub
 
Upvote 0
In your original code the name of your table is "Table_Rawdata" and now it is "Table1".
I have problems with the ID column, but it is already solved.
Try this:

Code:
Sub Fill_Report()
    Dim ws1 As Worksheet, ws2 As Worksheet
    Dim answer As Range
    Dim q As Long, j As Long, initial As Long
    
    Application.ScreenUpdating = False
    
    Set ws1 = Sheets("Rawdata")
    Set ws2 = Sheets("Report")
    
    'clear old report data
    ws2.Rows("3:" & Rows.Count).ClearContents
    'ws2.ListObjects("Report").Resize Range("$A$2:$I$3")
    
    q = 1   'Initial question number
    j = 3   'Initial row target
    
    'Column C initial question To column AR end question
    initial = ws1.Range("[COLOR=#ff0000]Table1[/COLOR][#All]").Cells(1, 1).Row
    For i = Columns("C").Column To Columns("AR").Column
        For Each answer In ws1.Range("[COLOR=#ff0000]Table1[/COLOR][" & ws1.Cells(initial, i).Value & "]").Cells
            If answer.Value Like "No*" Then
                ws2.Cells(j, "A").Value = "Q." & q                                                      'question ID
                ws2.Cells(j, "B").Value = "Category"                                                    'category
                ws2.Cells(j, "C").Value = "Deatiled Question Description"                               'question
                ws2.Cells(j, "D").Value = ws1.Cells(1, i).Value                                         'list field
                ws2.Cells(j, "E").Value = ws1.Cells(answer.Row, Range("Table1[[Name]]").Column)  'name
                ws2.Cells(j, "F").Value = answer.Value                                                  'Correctable/Not Correctable
                ws2.Cells(j, "G").Value = [COLOR=#ff0000]ws1.Cells(answer.Row, 1)    'ID[/COLOR]
                ws2.Cells(j, "H").Value = ws1.Cells(answer.Row, Range("Table1[[TNDNotes]]").Column)  'Notes
                ws2.Cells(j, "I").Value = ws1.Cells(answer.Row, Range("Table1[[CorrectionsMade]]").Column)   'CorrectionMade
                j = j + 1
            End If
        Next
        q = q + 1
    Next
    
    Application.ScreenUpdating = True
    
    MsgBox "End"
End Sub

Review the file below
https://www.dropbox.com/s/4iur739oaantsnk/Correrrreport dam.xlsm?dl=0
 
Last edited:
Upvote 0
Many, many thanks! I will try it out on first thing on Tuesday. I will keep you.posted!



In your original code the name of your table is "Table_Rawdata" and now it is "Table1".
I have problems with the ID column, but it is already solved.
Try this:

Code:
Sub Fill_Report()
    Dim ws1 As Worksheet, ws2 As Worksheet
    Dim answer As Range
    Dim q As Long, j As Long, initial As Long
    
    Application.ScreenUpdating = False
    
    Set ws1 = Sheets("Rawdata")
    Set ws2 = Sheets("Report")
    
    'clear old report data
    ws2.Rows("3:" & Rows.Count).ClearContents
    'ws2.ListObjects("Report").Resize Range("$A$2:$I$3")
    
    q = 1   'Initial question number
    j = 3   'Initial row target
    
    'Column C initial question To column AR end question
    initial = ws1.Range("[COLOR=#ff0000]Table1[/COLOR][#All]").Cells(1, 1).Row
    For i = Columns("C").Column To Columns("AR").Column
        For Each answer In ws1.Range("[COLOR=#ff0000]Table1[/COLOR][" & ws1.Cells(initial, i).Value & "]").Cells
            If answer.Value Like "No*" Then
                ws2.Cells(j, "A").Value = "Q." & q                                                      'question ID
                ws2.Cells(j, "B").Value = "Category"                                                    'category
                ws2.Cells(j, "C").Value = "Deatiled Question Description"                               'question
                ws2.Cells(j, "D").Value = ws1.Cells(1, i).Value                                         'list field
                ws2.Cells(j, "E").Value = ws1.Cells(answer.Row, Range("Table1[[Name]]").Column)  'name
                ws2.Cells(j, "F").Value = answer.Value                                                  'Correctable/Not Correctable
                ws2.Cells(j, "G").Value = [COLOR=#ff0000]ws1.Cells(answer.Row, 1)    'ID[/COLOR]
                ws2.Cells(j, "H").Value = ws1.Cells(answer.Row, Range("Table1[[TNDNotes]]").Column)  'Notes
                ws2.Cells(j, "I").Value = ws1.Cells(answer.Row, Range("Table1[[CorrectionsMade]]").Column)   'CorrectionMade
                j = j + 1
            End If
        Next
        q = q + 1
    Next
    
    Application.ScreenUpdating = True
    
    MsgBox "End"
End Sub

Review the file below
https://www.dropbox.com/s/4iur739oaantsnk/Correrrreport dam.xlsm?dl=0
 
Upvote 0

Forum statistics

Threads
1,214,918
Messages
6,122,241
Members
449,075
Latest member
staticfluids

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top