'Find' code question

sitewolf

Active Member
Joined
May 4, 2012
Messages
304
I have files that I update every month. I created pivot tables to accomplish what is needed, but some users insist on still seeing the information the way they'd always done before I came along......hundreds of lines of general ledger coding split into groups by various criteria.

I've also been steering away from macros because they're disabled by our admins, however I recently realized I can put some in my personal macros workbook.

Anyway, at certain changes in accounting codes, I insert 2 blank rows- one to put in subtotals, the second for a break between groups. Then I autosum and format monthly and ytd amounts for the group. Currently, I have a macro that inserts the 2 blank rows, moves to the columns with the amounts, and does the autosum/formatting. My 'problem' is that the amounts in some files are 1 column different than other files- monthly and ytd is in columns J and K in some, in K and L in others.

So, while I can just have 2 versions of the macro, the ideal would be 1...and that brings me here. The one constant in all these lines in all these files is that a 4 digit year is always in the last (rightmost) column with the monthly and ytd amounts always 3 and 2 columns to the left. Therefore, if I can 'find' the 4 digit year in the row above the newly inserted blank rows, then move down a row, left 3 and 2 columns, THEN autosum/format, I'd only need the one version.

Clear as mud?
Example of a line:
[TABLE="width: 578"]
<tbody>[TR]
[TD]1000[/TD]
[TD="align: right"]5200000[/TD]
[TD]0[/TD]
[TD]0[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]1900000[/TD]
[TD] J02 [/TD]
[TD] 08 [/TD]
[TD] 228.96 [/TD]
[TD] 610.28 [/TD]
[TD]04[/TD]
[TD]2017[/TD]
[/TR]
</tbody><colgroup><col><col><col span="2"><col span="2"><col><col><col><col span="2"><col><col></colgroup>[/TABLE]
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
If they all have constant headers you could use something like what was recently suggested in answer to another question here
 
Upvote 0
If the year is in the last column, you could use Cells(rowNumber, Columns.Count).End(xlToLeft) to find the last cell in row rowNumber.
Then use .Offset(0, -2) and .Offset(0, -3) to find the proper column for the ytd and monthly values.
 
Upvote 0

Forum statistics

Threads
1,224,550
Messages
6,179,463
Members
452,915
Latest member
hannnahheileen

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top