Run the macro in the attached workbook with {CTRL} + t
As requested range determination has been amended as follows:
- VBA looks leftwards from the last column of the worksheet until it finds an occupied cell in row1 (=last column)
- VBA looks upwards from the last row of the worksheet until it finds an occupied cell in Column "A" (=last row)
So that means that your last column must have a header in row1 and your last row must have a value in column "A")
Will this always be the case?
I have also reduced the strain on memory by amending the copy/paste line to
This means that it is only copying the columns in the data range.
I had been lazy and (by using .cells as the original range) was asking VBA to copy all the way across to column "XFD", which made your computer splutter!
Test database expanded to include blank columns "H" and "M"
Formula =IFERROR(SEARCH("P1",E2),"") is included in column "AA" simply allow me to check the results quickly.
Bookmarks