reshape grid for sumif calculations in vba

DrewsterUK

New Member
Joined
Jan 25, 2019
Messages
5
Hi all

I have a report that comes to me in several 'grids' in a workbook, and in order to report on it properly I need to make a small reshape.

OaX4kdh
https://imgur.com/OaX4kdh

These grids appear in one worksheet but have varying row lengths all the way down (separated by one blank row). I need to insert a blank column A, then add the firstname lastname in column F to each row between Job Board and TOTAL. the number of rows between job board and total varies from 1 to 10, but otherwise the structure of the grid doesn't change.

Can anyone help please?
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Hi & welcome to MrExcel.
How about
Code:
Sub DrewsterUK()
   Dim Rng As Range
   Range("A:A").Insert
   For Each Rng In Range("B:B").SpecialCells(xlConstants).Areas
      Rng.Offset(2, -1).Resize(Rng.Count - 3).Value = Rng.Offset(, 5).Resize(1, 1).Value
   Next Rng
End Sub
 
Last edited:
Upvote 0
Hi Fluff

Thanks for the post. It creates the cell in column A but doesn't move the firstname lastname into the relevant cells in Column A between job board and total - i get runtime error 1004; application defined or object-defined error
 
Upvote 0
Will your blocks of data always have at least 4 rows?
Also is there anything above the first block?
 
Upvote 0
to illustrate, this is where I got to so far...

Code:
Columns("A:A").Insert Shift:=xlToRight
For Each cell In Columns("G").Cells.SpecialCells(xlCellTypeConstants)

If cell.Value Like "* *" Then cell.Offset(2, -6).Range("A1").Value = cell.Value
cell.Offset(2, -6).Range("A1").Select

Next cell

unfortunately it's a complete mess of a report that gets generated in this horrible format. my code puts the name in the correct first position, but i cant work out how to then autofill down the correct number of rows because that number can vary each time.

the tables start a few rows down after some meaningless summary text and then will always follow the same format along the top row and the left column. The number of rows varies, but there is always

Overview
Job Board
-(optional row)
-(optional row)
-(optional row)
Total

so I guess there's a minimum of 4 rows, but no no minimum of the total number of mini-tables. once you've inserted blank column A, firstname-lastname is always in column G
 
Upvote 0
Will the summary text always be the same number of rows?
If not will it always have data in col A (col B after the insert)?
 
Upvote 0
Will the summary text always be the same number of rows?
If not will it always have data in col A (col B after the insert)?

grids start as you see them on row 3. row 1 contains summary information, row 2 is blank.

the earliest position that 'firstname lastname' COULD appear is G3 (after the column insert).
after the insert, there is always data in column B

after these edits, my sumif formulae reference Column A & Column B
 
Upvote 0
In that case try
Code:
Sub DrewsterUK()
   Dim Rng As Range
   Range("A:A").Insert
   For Each Rng In Range("B2:B" & Rows.Count).SpecialCells(xlConstants).Areas
      Rng.Offset(2, -1).Resize(Rng.Count - 3).Value = Rng.Offset(, 5).Resize(1, 1).Value
   Next Rng
End Sub
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,333
Members
452,636
Latest member
laura12345

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