Ok, maybe "correctly" is the right word, but not as how I would like it to work.
I have a sheet (sheet7) with data that I would like to loop through and export the values in that row if the value in column A is equal to something. The loop below is almost working, but instead of checking the value in column A, exporting the row, and then moving onto the next row, it just exports that row over and over in the table, and then exports the next correct row on top of that one over and over.
NumFu = Application.CountIf(Sheet7.Range("A:A"), Sheet6.Range("A2").Value) //// numfu is the number of times the value I'm checking for appears in column A of sheet 7. it will be the number of rows in the table
Dim R As Integer, co As Integer, TR As Integer ////R is the number of rows in sheet7 that it loops through, TR is rows in the table being exported, ///and co is the column of the table
Set oTable = ActiveDocument.Tables.Add(ActiveDocument.Bookmarks("Table").Range, NumFu, 4)
oTable.Range.ParagraphFormat.SpaceAfter = 6
For R = 1 To 55
For TR = 1 To NumFu
For co = 1 To 1
If Sheet7.Range("A" & (R)) = Sheet6.Range("A2") Then
oTable.Cell(TR, co).Range.Text = Sheet7.Range("D" & (R))
Else
End If
Next
Next
For co = 2 To 2
If Sheet7.Range("A" & (R)) = Sheet6.Range("A2") Then
oTable.Cell(TR, co).Range.Text = Sheet7.Range("E" & (R))
Else
End If
Next
Next
So it should go down column A of sheet 7, and for every Row where cell A&R = a sheet2 A2, then export the column D Row R to the table, and move onto the next row.
Bookmarks