1

I have two columns with data. Each cell is formatted: "***" or "XXX at mm.dd.yyyy", where XXX represent various numeric combinations, and I need to replace "XXX at mm.dd.yyyy" with "XXX", so I've done this:

For Each c In Range(.Cells(2, 9), .Cells(finalrow, 10))
        If c <> "***" Then
            c.Value = Split(c, " at")(0) * 1
        End If
Next c

but I get a 'Subscript out of range' error on the row 2345.

What am I missing here?

8
  • 1
    What is row 2345? Commented Dec 19, 2017 at 10:01
  • Might be a blank cell, or value that doesn't fin into "***" format but doesn't have at delimitier. The problem is that that array you create doesn't have any items at all. Temporary fix is to add condition If Ubound(Split(c, " at") >=0 Then Commented Dec 19, 2017 at 10:02
  • Yes, that's it, there was a blank cell in the row 2330. It's my mistake. Commented Dec 19, 2017 at 10:05
  • 1
    @CreakushColiko so row 2345 actually meant your row in Excel? I am impressed. Commented Dec 19, 2017 at 10:07
  • 1
    Welcome! Please check out the tour and also see How to Ask as well as minimal reproducible example prior to making an edit to your question or before your next post. Thanks! Commented Dec 19, 2017 at 10:09

1 Answer 1

5

Concerning that you probably get an error because of the empty 2345 row:

For Each c In Range(.Cells(2, 9), .Cells(finalrow, 10))
        If c <> "***" Then
            If InStr(1, c, " at ") Then
                c.Value = Split(c, " at")(0)
            End If
        End If
Next c

It checks whether there is " at " in c, thus the split will not result in an error.

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

Comments

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.