from the bottom up...

tourless

Board Regular
Joined
Feb 8, 2007
Messages
144
Office Version
  1. 365
Platform
  1. Windows
Hi Folks,

I'm looking for a snip of a macro that will look to column Q, from the last row up, and when it no longer encounters the value 'Q', add a row above that last instance. My list is already sorted but the major requirement is to search from the last row up.
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
from the last row up, and when it no longer encounters the value 'Q', add a row above that last instance

That reads like you are looking for the first instance of "Q" in column Q. Do you actually mean that you want to insert a row above the last instance of "Q" in column Q?
 
Upvote 0
That reads like you are looking for the first instance of "Q" in column Q. Do you actually mean that you want to insert a row above the last instance of "Q" in column Q?

That is correct Mark. It just so happens that cells in column Q contain either 'A' or 'Q' for their values.
 
Upvote 0
Code:
Columns("Q").Find("Q", , xlValues, , xlRows, xlPrevious).EntireRow.Insert
 
Upvote 0
Please note if by contains you mean there is other data in the cell other than "Q" Then you need to explain what the data looks like.
 
Last edited:
Upvote 0
I'm really bad at describing my problem. Your code work perfectly and did exactly what I asked, but what I asked isn't exactly what I needed. My data is made up of two sets of data, the first set contains information for customers that started in 2018, of which there can and are instances of Q mixed in with A in column Q. The second data set is made up of only customers where the value in column Q will be Q. So it looks sort of like this...

A - 1st set result
A - 1st set result
A - 1st set result
Q - 1st set result
A - 1st set result
A - 1st set result
Q - 1st set result
A - 1st set result
Q - 2nd set result
Q - 2nd set result
Q - 2nd set result
Q - 2nd set result
Q - 2nd set result

What I actually needed was to find the first instance of A in column Q and insert a row before that...

A - 1st set result
A - 1st set result
A - 1st set result
Q - 1st set result
A - 1st set result
A - 1st set result
Q - 1st set result
A - 1st set result

Q - 2nd set result
Q - 2nd set result
Q - 2nd set result
Q - 2nd set result
Q - 2nd set result

I was able to accomplish this by tweaking your code to this...
Code:
Columns("Q").Find("A", , xlValues, , xlRows, xlPrevious).Offset(1).EntireRow.Insert Shift:=xlDown

Thank you Mark.
 
Upvote 0
Ignore as what you call first, I call last. Btw the default for entirerow.insert is shift:=xldown so you didn't need to add that part.
 
Last edited:
Upvote 0
Solution

Forum statistics

Threads
1,223,228
Messages
6,170,876
Members
452,363
Latest member
merico17

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