I am trying to come up with a formula that can be run in a different worksheet and references the data below.
Essentially for each cell in D, I want to check upwards and when I find the string “Invoice” I select the next row above and column B. Essentially I’d be finding the company name each time. As you can see, the number of rows of records for each company may vary.
More simply, the formula could just work on column B and return the string directly above the first occurrence of the string “Status”.
I dislike how complicated this is, but I have no control over the data format I am receiving and the source refuses to change it.
Original Data
A B C D
1 ABC Widgets, Inc.
2 Account Status Date Invoice
3 1423 Open 4/25/2011 123748
4 1423 Closed 5/1/2011 432741
5 1423 Open 5/2/2011 522211
6
7 XYZ Sprockets, Inc.
8 Account Status Date Invoice
9 3222 Open 5/3/2011 529999
10
Finished Data
A B C D E
2 Account Status Date Invoice Client
3 1423 Open 4/25/2011 123748 ABC Widgets, Inc.
4 1423 Closed 5/1/2011 432741 ABC Widgets, Inc.
5 1423 Open 5/2/2011 522211 ABC Widgets, Inc.
9 3222 Open 5/3/2011 529999 XYZ Sprockets, Inc.
Nutch,
While I can’t get your VBA code to work properly (see comments) it did allow me to come up with this code that finds the first occurrence of “Status” and then offsets 1 cell above. This is essentially what I am trying for but in Formula format.
Sub findFirstStringAbove()
'
Cells.Find(What:="Status", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, MatchCase _
:=False).Offset(-1, 0).Select
End Sub
Try this formula, entered as an array formula, i.e. with Ctrl+Shift+Enter, then copied down.
To run it from another sheet, cut and paste it from your original sheet and it will adjust the reference automatically.