1

Trying to select header / first row and data under it from columns C to O Until the first cell in column C has the word "Estimated" I came up with this VBA code based on another answer on stackoverflow, but it doesn't seem to be working

All help is deeply appreciated!!

Range("C1").Select
For i = 1 To 9999
If ISNUMBER(SEARCH(ActiveCell.Offset(0, i), "Estimated")) = TRUE Then Exit For
If ISNUMBER(SEARCH(ActiveCell.Offset(0, i), "Estimated")) = FALSE Then Exit For
Next
If ISNUMBER(SEARCH(ActiveCell.Offset(0, i), "Estimated")) = TRUE Then             
    Range(Cells(ActiveCell.Row, 15), Cells(ActiveCell.Row, ActiveCell.Column + i - 1)).Select

`

1

2 Answers 2

1

Try,

range(cells(1, "C"), cells(application.match("Estimated", columns(3), 0)-1, "O")).select

Not sure from your narrative whether the row containing "Estimated" was to be included or not. The -1 tells it not to include the "Estimated" row.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the response. it is supposed to exclude it. When I ran it, I got "type mismatch" as an error.
0

you could use

Range("O1", Columns(3).Find("Estimated", , xlValues, xlPart)).Select ' to include row with "Estimated" in column C

or

Range("O1", Columns(3).Find("Estimated", , xlValues, xlPart).offset(-1)).Select ' to exclude row with "Estimated" in column C

2 Comments

Thanks for having both of them. I used the second one, but when I ran it, I got "object variable or with block variable not set" as an error.
Is “Estimated” possibly not there?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.