Logo 
Search:

MS Office Answers

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds
  Question Asked By: Ryan Anderson   on Jan 15 In MS Office Category.

  
Question Answered By: Jakson Williams   on Jan 15

Re:"macro will notify the user  to edit  the data"
Relatively easily, see example  code below.

Re:"how macro  could extract  the text  in a colomn to 5 colomn"
As I think you want it; with difficulty. How will the computer know to
split the string between 'Kaugan' and 'PT', when if 'PT' was to be
included in the first split 'Mr Sangeta kaugan PT' is still only 20
characters? If this is done then the next string is NOT too long?!
I think Kaugan is the person's last name, but how will the computer
know this?

Anyway, I've begun to write some code to give you some ideas; it works
on the selected cell(s) and places strings in the 5 (or more) columns
to the right, trying to get as close to 25 characters  in each cell as
it can, assuming the string is to be split using spaces  as delimiter:

Sub blah()
For Each cll In Selection.Cells
p = Split(Application.Trim(cll), " ")
StringNo = 1
i = 0
Do
myStr = ""
Do
myStr = Application.Trim(myStr & " " & p(i))
i = i + 1
Loop Until i >= UBound(p) Or Len(Application.Trim( _
myStr & " " & p(i))) >= 25
If Len(myStr) < 26 Then
cll.Offset(, StringNo) = myStr
Else
Do
result = InputBox("You need to remove " & Len(myStr _
) - 25 & " characters. Do this now", _
"Needs trimming a bit", myStr)
If result <> "" Then myStr = result
Loop Until Len(myStr) < 26
cll.Offset(, StringNo) = myStr
End If
StringNo = StringNo + 1
Loop Until i >= UBound(p)
Next cll
End Sub

Share: 

 

This Question has 2 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on Extract text in a colomn to 5 colomn Or get search suggestion and latest updates.


Tagged: