I'm new to Excel VBA and was looking for some help in fixing my code. So basically to provide colour on what I have, I have an excel database, and a word document. In the word document I have bookmarked section headers (reffered to as "cat", "dog", and "bird") and in a row on the excel database I have "dog" and "bird".
What I am trying to do is write a code that compares the elements of the array (which are strings) to the cell values within a range declared in an excel database. For the values that exist in the array but not in the declared excel range, I want to delete those values (i.e. the bookmark) from the word document.
If anyone could provide me with feedback, ideas, or example codes it would be greatly appreciated.
Thanks.
Sub ArrayToDatabase()
Dim myRange As Variant
Set myRange = Range("C7:AP7")
Dim myArray As Variant
myArray = Array("cat", "dog", "bird")
Dim i As Integer
Dim reqName As Object
For i = LBound(myArray) To UBound(myArray)
Set reqName = myArray(i).Value
If myRange.Validation(reqName) = False Then
wdApp.ActiveDocument.Bookmarks(reqName).Range._
Paragraphs(1).Range.Delete
End If
Next i
End Sub