Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 6
Default A further problem that I am struggling with

I have a 800 row of data in each 8th row there is the same information.
The information shows the name of the business and the proprietor
The proprietor title is ALWAYS Mr. Mrs. or Miss

JOHNS FRUIT SHOP MR JOHN BROWN

MARYS CAKE SHOP MISS MARY SMITH

What I want to is break the info into two fields, breaking it on the title
Mr Mrs or Miss and (if it is possible) insert the name data into the next
row

So originally it will be:

Row 81 JOHNS FRUIT SHOP MR JOHN BROWN

and it will then appear as:

Row 81 JOHNS FRUIT SHOP
Row 82 MR JOHN BROWN

One problem that may appear is as soon as the macro spilt my original data
cluster of 8 rows it will then become 9 rows

A possible solution may be 2 macros, one to split the data into another Col.
(B) and then a second macro to reinsert it into row 9 with a progressive +1

A big ask for a Sunday morning!

Regards
Stephen
Gold Coast, Australia

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 5,651
Default A further problem that I am struggling with

On Sun, 09 Aug 2009 01:52:32 GMT, "Its me" wrote:

I have a 800 row of data in each 8th row there is the same information.
The information shows the name of the business and the proprietor
The proprietor title is ALWAYS Mr. Mrs. or Miss

JOHNS FRUIT SHOP MR JOHN BROWN

MARYS CAKE SHOP MISS MARY SMITH

What I want to is break the info into two fields, breaking it on the title
Mr Mrs or Miss and (if it is possible) insert the name data into the next
row

So originally it will be:

Row 81 JOHNS FRUIT SHOP MR JOHN BROWN

and it will then appear as:

Row 81 JOHNS FRUIT SHOP
Row 82 MR JOHN BROWN

One problem that may appear is as soon as the macro spilt my original data
cluster of 8 rows it will then become 9 rows

A possible solution may be 2 macros, one to split the data into another Col.
(B) and then a second macro to reinsert it into row 9 with a progressive +1

A big ask for a Sunday morning!

Regards
Stephen
Gold Coast, Australia


Not too tough but your description is inconsistent.

In your request, you write:

"The proprietor title is ALWAYS Mr. Mrs. or Miss"

But in your data sample, you show " MR " or " MISS " (all caps, no ".", and a
space before and after the title).

I assumed that
the title could be upper or lower case
the title did NOT have the "." after
the title was always surrounded by <space's
the title was the first word that looked like one starting from the
right.

If the data is different, some modifications may be necessary.

I also assumed that the eighth row after the end of the data was blank. Again,
if data is different, a different test will need to be used.

If the data varies so that every eighth row is NOT a Business Name --
Proprietor row, again, changes will be required.

But this should get you started.

Read the comments carefully so as to more easily modify this to your
particulars.

To enter this Macro (Sub), <alt-F11 opens the Visual Basic Editor.
Ensure your project is highlighted in the Project Explorer window.
Then, from the top menu, select Insert/Module and
paste the code below into the window that opens.

To use this Macro (Sub), <alt-F8 opens the macro dialog box. Select the macro
by name, and <RUN.

===============================
Option Explicit

Sub SplitProprietor()
Dim c As Range
Dim sBusName As String
Dim sProprietor As String
Dim lTitle As Long

'set c to first cell in range to be altered
Set c = Range("A1")

'go to first cell to be split
Set c = c.Offset(rowoffset:=7)

'start Do loop

Do

'get the two parts
'where is the Title?
lTitle = TitlePos(c.Value)
If lTitle = 0 Then
MsgBox ("Data Error at " & c.Address)
Exit Sub
End If
sBusName = Left(c.Value, lTitle - 1)
sProprietor = Mid(c.Value, lTitle + 1)

'move cells down
c.Insert (xlShiftDown)

'insert split data
c.Offset(rowoffset:=-1).Value = sBusName
c.Value = sProprietor

'go to next possible cell to split
Set c = c.Offset(rowoffset:=8)

'check if at end
Loop Until c.Value = ""
End Sub
Private Function TitlePos(s As String) As Long
Dim sTitles As Variant
Dim i As Long
sTitles = Array(" MRS ", " MR ", " MISS ")
For i = 0 To UBound(sTitles)
TitlePos = InStrRev(s, sTitles(i), -1, vbTextCompare)
If TitlePos 0 Then Exit For
Next i
End Function
===================================
--ron
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 5,651
Default A further problem that I am struggling with

On Sat, 08 Aug 2009 22:59:18 -0400, Ron Rosenfeld
wrote:

Private Function TitlePos(s As String) As Long
Dim sTitles As Variant
Dim i As Long
sTitles = Array(" MRS ", " MR ", " MISS ")
For i = 0 To UBound(sTitles)
TitlePos = InStrRev(s, sTitles(i), -1, vbTextCompare)
If TitlePos 0 Then Exit For
Next i
End Function


This part should, more properly, be written as:

=======================
Private Function TitlePos(s As String) As Long
Dim sTitles As Variant
Dim i As Long
sTitles = Array(" MRS ", " MR ", " MISS ")
For i = LBound(sTitles) To UBound(sTitles)
TitlePos = InStrRev(s, sTitles(i), -1, vbTextCompare)
If TitlePos 0 Then Exit For
Next i
End Function
========================

--ron
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help me solve this problem I've been struggling with for so long! Bjørn Excel Worksheet Functions 5 October 3rd 08 09:24 PM
Struggling to plot where I want Scooby Jones Charts and Charting in Excel 3 October 31st 06 12:46 PM
Struggling IF value Rebecca Excel Discussion (Misc queries) 5 April 6th 06 09:52 PM
Struggling Again With A VLOOKUP JohnK Excel Worksheet Functions 3 August 23rd 05 07:41 AM
Help, I'm Struggling! Fybo New Users to Excel 1 March 4th 05 07:57 PM


All times are GMT +1. The time now is 05:39 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"