Error In Text Manipulation Formula

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,538
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I am having a difficult resolving the error in this code:

Rich (BB code):
For pp = lRowst To lRowed
    .Range("Q" & pp) = Application.Left(.Range("B" & pp), (Application.Find("-", .Range("B" & pp) - 1)))
Next pp

I am getting a 'Wrong number of arguments or invalid property assignment.' error with the highlighted term.

Source:
B&pp (B24) = 9:00A-9:30A

Result:
Q&pp (Q24 = 9:00A
 
Last edited:

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Try

Code:
    .Range("Q" & pp).Value = Left(.Range("B" & pp).Value, InStr(.Range("B" & pp).Value, "-") - 1)
 
Upvote 0
I believe the issue is where your -1 falls in your Find() function. Do you maybe want B"pp-1" instead of the cell B"pp" - 1?
 
Upvote 0
Hi Peter, yes ... that was what I needed.
Always appreciate you help.
 
Upvote 0
Thanks s hal for your reply. Appreciated!

This procedure has added another hurdle. The value this formula creates is text and being so, does not allow me to to sort by time.
What addition do I need to make that text string into a usable time value? The value doesn't need any specific formula, it just has to be a valid time value for sorting.
 
Upvote 0
Try

Code:
.Range("Q" & pp).Value = TimeValue(Left(.Range("B" & pp).Value, InStr(.Range("B" & pp).Value, "-") - 1))
 
Upvote 0
Rich (BB code):
For pp = lRowst To lRowed
    .Range("Q" & pp) = Application.Left(.Range("B" & pp), (Application.Find("-", .Range("B" & pp) - 1)))
Next pp
You can do what you intended with the above code much faster without using a loop at all (I also added statements to make your text values into time values)...

Rich (BB code):
With .Range("Q" & lRowst & ":Q" & lRowed)
  .Value = .Range("B" & lRowst & ":B" & lRowed).Value
  .Replace "-*", "", xlPart
  .Replace "A", " A", xlPart
  .Replace "P", " P", xlPart
End With

This With/End.With block would be nested inside the With/End.With block that the "dots" in your original code refer back to.
 
Upvote 0
That was quick ... and painless. Thanks again Peter.
 
Upvote 0
Hi Rick ... thanks for sharing your method. Certainly something for me to digest as an educational opportunity. I'm amazed of how many different ways there are to do things.
 
Upvote 0

Forum statistics

Threads
1,203,240
Messages
6,054,316
Members
444,717
Latest member
melindanegron

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