0

I'm trying to read data off a few files and create a new document containing the read data, which is easy enough using the workbook object.

However, I'm not sure how to only add data which has not been added yet without overwriting the previously written data.

Any help would be greatly appreciated, thanks in advance.

2
  • Is the data being overwritten the same as the data replacing it? Commented Jul 9, 2015 at 20:12
  • For the most part yes, only each element of the list I create will have a timestamp corresponding to the time it was added to the list. Commented Jul 9, 2015 at 20:27

1 Answer 1

2

You could read your data into a Dictionary object first. Dictionaries can be used to store a unique list of items. For example:

Dim d As Object
Set d = CreateObject("Scripting.Dictionary")

' Loop thru your file data, adding each value if it doesn't exist...
    If Not d.Exists(strData) Then d.Add strData, ""
' End loop

' Now add each dictionary item to your workbook...
Dim k As Variant
For Each k In d
    ' Add k to workbook
Next
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, I'll look into the dictionary object
Adding "Microsoft Scripting Runtime" to the VBA References adds the Dictionary object to IntelliType in the Editor which is handy if your learning about them. CreateObject is probably the best way over all as its more portable.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.