Copy a range determined by a keyword

yoda_pooh

Board Regular
Joined
Oct 12, 2007
Messages
72
Good morning or evening depending where you're located,

I have a sheet where I need to select a range of data from A1 to AExx. The row value of AE is determined by the creative keyword "stop." The word "stop" appears in column AF where the last row appears that meets my criteria. I also have a cell reference that returns the row number where the word "stop" occurs. So, the selection could be done by finding the instance of the word "stop" by searching column AF or by referencing cell AH2 (which contains the row number) to determin the last row of the range. Either way is fine withh me.


Thanks for any help,

Jeremy
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Macro? Or Formula?

Formula

Code:
    =Indirect("A1:AE" & Match("stop",AF:AF,0))

or
Code:
    =Indirect("A1:AE" & AH2)

Macro

Code:
 Range("A1", Range("AE" + Range("AH2").Value)).Copy  [I]enter destination here[/I]
 
Upvote 0
Thank you Jimmy90. It's part of a macro but when I pasted what you gace me, I get a type mismatch error.

This is the macro so far
Sheets("Export").Select
Cells.Select
Selection.ClearContents
Range("A1").Select
Sheets("For Merge").Select
*** Range("A1", Range("AE" + Range("AH2").Value)).Copy *** Your line
lastrow = Cells(Rows.Count, "AF").End(xlUp).Row ***Disabled this when your code was in
MyRange = "A1:AE" & lastrow ***Disabled this when your code was in
Range(MyRange).Copy ***Disabled this when your code was in
Sheets("Export").Select
Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
ActiveWorkbook.Worksheets("Export").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Export").Sort.SortFields.Add Key:=Range("J2:J131") _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("Export").Sort.SortFields.Add Key:=Range("G2:G131") _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("Export").Sort.SortFields.Add Key:=Range("F2:F131") _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Export").Sort
.SetRange Range("A1:AE131")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub

Code was done with combination of macro record and some code, hence the mess.

Thanks
 
Upvote 0
I've modified my AH column so AH2 now gives a numeric value of the last row (in this case 131 -but this fluctuates)
AH3 contains =("A2:"&AH"&AH2) to give A2:AH131
AH4 converts the value in AH3 to text

Would that help at all?
 
Upvote 0
Previous solution offered is returning an error.

Hi I'm looking for a way to have my macro select from A2 to AExx. The row is determined by where the word "stop" appears in column AF.

I do have a cell that determines this via formula (AH4) but I'm not sure if that would help or not in the macro formation.

Thanks in advance.
 
Upvote 0

Forum statistics

Threads
1,213,489
Messages
6,113,953
Members
448,535
Latest member
alrossman

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