I try to get my finances together and for that downloaded my data from the local bank as excel. As it is pretty wild (and some years), I want display the data summed up for what I use my money for, as "food", "rent" and stuff. For that I want to go through all the rows and check if a certain cell in the row contains any known word, where I know where to put it in my expenses.
For example: if there is the name of a restaurant in a certain cell, it is a food expense, but the same if it is walmart for example.
I came up with something like:
Dim food() As String
food(0) = "Nespresso"
food(1) = "Spar"
food(2) = "Billa"
Dim SrchRng As Range, cel As Range
Set SrchRng = Range("I3:I9")
For Each cel In SrchRng
If InStr(1, cel.Value, food(0)) Or InStr(1, cel.Value, food(1)) Or InStr(1, cel.Value, food(2)) > 0 Then
cel.Offset(0, 3).Value = "Essen/Trinken"
Else
cel.Offset(0, 3).Value = "-"
End If
Next cel
But there are some problems with the code:
- if all the variables are in a array, there certanly is a way to not be specific and go through array(0), (1), ... but I don't know how.
- to make it more "editable" and convenient, I don't want to hardcode it, but have a 2nd sheet which displays "food" in A1 and on A2-n the different variables for food(0)-food(n-2) should be used.
- using the range to a fixed amount also is not a good way how to make sure to work on any given data, it would be best to check for the last row with data first
I already found ways to come to answer point 3 tho.
Everything would help. Thanks in advice :)