Welcome to the { mindfrost82.com } forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.

Go Back   { mindfrost82.com } > Gadget Corner > Tech Newsgroups > Microsoft > MS Office > Excel

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-26-2008, 04:32 PM
NickTheBatMan
 
Posts: n/a
Can I make a Macro do the following for me ?

I have a sheet of data where in column C I want to insert Chr10 in
each cell at the point where if I'm doing it manually I F2 to edit the
cell then Ctrl L Arrow thrice...

I've tried recording a Macro to do this but it just includes the text
of the particular cell that I'm currently editing and inserts the
Chr10 in where I have done it manually without telling me how to do
what I want....

I'd like to do it with a Macro as I've 1700ish rows to do and am
starting to get RSI from it :(

Eventually this will be saved as a CSV file so there'll be nothing
Excel in it...

Any help gratefully received :)

Nick
Reply With Quote
  #2 (permalink)  
Old 05-26-2008, 05:28 PM
=?Utf-8?B?R2FyeScncyBTdHVkZW50?=
 
Posts: n/a
RE: Can I make a Macro do the following for me ?

Let's pick a cell and enter:

go to alpha ralpha blvd

If we select the cell and touch F2 and then CNTRL-BACKARROW three times, the
editting cursor will be just before the alpha and this is where the Chr(10)
will go. Try this simple macro:

Sub batman()
For Each r In Selection
s = Split(r.Value, " ")
s(UBound(s) - 2) = Chr(10) & s(UBound(s) - 2)
r.Value = Join(s, " ")
Next
End Sub

--
Gary''s Student - gsnu2007i


"NickTheBatMan" wrote:

> I have a sheet of data where in column C I want to insert Chr10 in
> each cell at the point where if I'm doing it manually I F2 to edit the
> cell then Ctrl L Arrow thrice...
>
> I've tried recording a Macro to do this but it just includes the text
> of the particular cell that I'm currently editing and inserts the
> Chr10 in where I have done it manually without telling me how to do
> what I want....
>
> I'd like to do it with a Macro as I've 1700ish rows to do and am
> starting to get RSI from it :(
>
> Eventually this will be saved as a CSV file so there'll be nothing
> Excel in it...
>
> Any help gratefully received :)
>
> Nick
>

Reply With Quote
  #3 (permalink)  
Old 05-26-2008, 07:56 PM
NickTheBatMan
 
Posts: n/a
Re: Can I make a Macro do the following for me ?

Mm, either I've got the wrong end of this or it don't do what I was
hoping for...

It's putting Chr10 - a CR - at the beginning of the cell, or if I
select several cells it progresses to the next cell and puts the next
space in the text until it runs out of text then it fails...

Here's some of the text from the cells: -

WHITEHOUSE FPS-DSN2-015-1672
WEST DYKE ROAD MCG-DSN3-022-1562
CHURCH LANE CCTV-DSN3-023-0440
GREEN LANE FPS-DSN3-024-1100
GREW GRASS UWC-DSN3-025-0110

As you can see there's not equal words to begin with, I want the CR
before the group that is held together by the - hyphen...

Nick

On 26 May, 17:28, Gary''s Student
<GarysStud...@discussions.microsoft.com> wrote:
> Let's pick a cell and enter:
>
> go to alpha ralpha blvd
>
> If we select the cell and touch F2 and then CNTRL-BACKARROW three times, the
> editting cursor will be just before the alpha and this is where the Chr(10)
> will go. Try this simple macro:
>
> Sub batman()
> For Each r In Selection
> s = Split(r.Value, " ")
> s(UBound(s) - 2) = Chr(10) & s(UBound(s) - 2)
> r.Value = Join(s, " ")
> Next
> End Sub
>
> --
> Gary''s Student - gsnu2007i
>
> "NickTheBatMan" wrote:
> > I have a sheet of data where in column C I want to insert Chr10 in
> > each cell at the point where if I'm doing it manually I F2 to edit the
> > cell then Ctrl L Arrow thrice...

>
> > I've tried recording a Macro to do this but it just includes the text
> > of the particular cell that I'm currently editing and inserts the
> > Chr10 in where I have done it manually without telling me how to do
> > what I want....

>
> > I'd like to do it with a Macro as I've 1700ish rows to do and am
> > starting to get RSI from it :(

>
> > Eventually this will be saved as a CSV file so there'll be nothing
> > Excel in it...

>
> > Any help gratefully received :)

>
> > Nick


Reply With Quote
  #4 (permalink)  
Old 05-26-2008, 08:17 PM
=?Utf-8?B?R2FyeScncyBTdHVkZW50?=
 
Posts: n/a
Re: Can I make a Macro do the following for me ?

Have patience...we are making good progress. Your examples removed part of
my confusion. We clearly do not need the -2

Try this new version instead:

Sub batman()
For Each r In Selection
s = Split(r.Value, " ")
s(UBound(s)) = Chr(10) & s(UBound(s))
r.Value = Join(s, " ")
Next
End Sub


1. replace the macro
2. select the cells
3. run the macro

Post back if more modifications are needed.
--
Gary''s Student - gsnu2007i


"NickTheBatMan" wrote:

> Mm, either I've got the wrong end of this or it don't do what I was
> hoping for...
>
> It's putting Chr10 - a CR - at the beginning of the cell, or if I
> select several cells it progresses to the next cell and puts the next
> space in the text until it runs out of text then it fails...
>
> Here's some of the text from the cells: -
>
> WHITEHOUSE FPS-DSN2-015-1672
> WEST DYKE ROAD MCG-DSN3-022-1562
> CHURCH LANE CCTV-DSN3-023-0440
> GREEN LANE FPS-DSN3-024-1100
> GREW GRASS UWC-DSN3-025-0110
>
> As you can see there's not equal words to begin with, I want the CR
> before the group that is held together by the - hyphen...
>
> Nick
>
> On 26 May, 17:28, Gary''s Student
> <GarysStud...@discussions.microsoft.com> wrote:
> > Let's pick a cell and enter:
> >
> > go to alpha ralpha blvd
> >
> > If we select the cell and touch F2 and then CNTRL-BACKARROW three times, the
> > editting cursor will be just before the alpha and this is where the Chr(10)
> > will go. Try this simple macro:
> >
> > Sub batman()
> > For Each r In Selection
> > s = Split(r.Value, " ")
> > s(UBound(s) - 2) = Chr(10) & s(UBound(s) - 2)
> > r.Value = Join(s, " ")
> > Next
> > End Sub
> >
> > --
> > Gary''s Student - gsnu2007i
> >
> > "NickTheBatMan" wrote:
> > > I have a sheet of data where in column C I want to insert Chr10 in
> > > each cell at the point where if I'm doing it manually I F2 to edit the
> > > cell then Ctrl L Arrow thrice...

> >
> > > I've tried recording a Macro to do this but it just includes the text
> > > of the particular cell that I'm currently editing and inserts the
> > > Chr10 in where I have done it manually without telling me how to do
> > > what I want....

> >
> > > I'd like to do it with a Macro as I've 1700ish rows to do and am
> > > starting to get RSI from it :(

> >
> > > Eventually this will be saved as a CSV file so there'll be nothing
> > > Excel in it...

> >
> > > Any help gratefully received :)

> >
> > > Nick

>
>

Reply With Quote
  #5 (permalink)  
Old 05-26-2008, 09:34 PM
Rick Rothstein \(MVP - VB\)
 
Posts: n/a
Re: Can I make a Macro do the following for me ?

I'm not sure if it is important to the OP or not, but your routine leaves a
trailing space at the end the first line formed by the split. I guess you
could use the Replace function like this to remove the trailing space...

Sub batman()
Dim r As Range
Dim s As Variant
For Each r In Selection
s = Split(r.Value, " ")
s(UBound(s)) = Chr(10) & s(UBound(s))
r.Value = Join(s, " ")
r.Value = Replace(r.Value, " " & Chr(10), Chr(10))
Next
End Sub

Here is an alternate subroutine which, as a by product of how it works, does
not introduce the trailing space in the first place...

Sub AddCR()
Dim Cell As Range
Dim Contents As String
For Each Cell In Range("A1:A5")
Contents = Cell.Text
Mid$(Contents, InStrRev(Contents, " ")) = vbLf
Cell.Value = Contents
Next
End Sub

Note my preference for the predefined VB constant vbLf instead of the
Chr(10) function call.

Rick


"Gary''s Student" <GarysStudent@discussions.microsoft.com> wrote in message
news:AFD80B0E-9E5E-4E31-BF24-70BFD38FD84B@microsoft.com...
> Have patience...we are making good progress. Your examples removed part
> of
> my confusion. We clearly do not need the -2
>
> Try this new version instead:
>
> Sub batman()
> For Each r In Selection
> s = Split(r.Value, " ")
> s(UBound(s)) = Chr(10) & s(UBound(s))
> r.Value = Join(s, " ")
> Next
> End Sub
>
>
> 1. replace the macro
> 2. select the cells
> 3. run the macro
>
> Post back if more modifications are needed.
> --
> Gary''s Student - gsnu2007i
>
>
> "NickTheBatMan" wrote:
>
>> Mm, either I've got the wrong end of this or it don't do what I was
>> hoping for...
>>
>> It's putting Chr10 - a CR - at the beginning of the cell, or if I
>> select several cells it progresses to the next cell and puts the next
>> space in the text until it runs out of text then it fails...
>>
>> Here's some of the text from the cells: -
>>
>> WHITEHOUSE FPS-DSN2-015-1672
>> WEST DYKE ROAD MCG-DSN3-022-1562
>> CHURCH LANE CCTV-DSN3-023-0440
>> GREEN LANE FPS-DSN3-024-1100
>> GREW GRASS UWC-DSN3-025-0110
>>
>> As you can see there's not equal words to begin with, I want the CR
>> before the group that is held together by the - hyphen...
>>
>> Nick
>>
>> On 26 May, 17:28, Gary''s Student
>> <GarysStud...@discussions.microsoft.com> wrote:
>> > Let's pick a cell and enter:
>> >
>> > go to alpha ralpha blvd
>> >
>> > If we select the cell and touch F2 and then CNTRL-BACKARROW three
>> > times, the
>> > editting cursor will be just before the alpha and this is where the
>> > Chr(10)
>> > will go. Try this simple macro:
>> >
>> > Sub batman()
>> > For Each r In Selection
>> > s = Split(r.Value, " ")
>> > s(UBound(s) - 2) = Chr(10) & s(UBound(s) - 2)
>> > r.Value = Join(s, " ")
>> > Next
>> > End Sub
>> >
>> > --
>> > Gary''s Student - gsnu2007i
>> >
>> > "NickTheBatMan" wrote:
>> > > I have a sheet of data where in column C I want to insert Chr10 in
>> > > each cell at the point where if I'm doing it manually I F2 to edit
>> > > the
>> > > cell then Ctrl L Arrow thrice...
>> >
>> > > I've tried recording a Macro to do this but it just includes the text
>> > > of the particular cell that I'm currently editing and inserts the
>> > > Chr10 in where I have done it manually without telling me how to do
>> > > what I want....
>> >
>> > > I'd like to do it with a Macro as I've 1700ish rows to do and am
>> > > starting to get RSI from it :(
>> >
>> > > Eventually this will be saved as a CSV file so there'll be nothing
>> > > Excel in it...
>> >
>> > > Any help gratefully received :)
>> >
>> > > Nick

>>
>>


Reply With Quote
  #6 (permalink)  
Old 05-26-2008, 10:01 PM
NickTheBatMan
 
Posts: n/a
Re: Can I make a Macro do the following for me ?

On 26 May, 20:17, Gary''s Student
<GarysStud...@discussions.microsoft.com> wrote:
> Have patience...we are making good progress. Your examples removed part of
> my confusion. We clearly do not need the -2
>
> Try this new version instead:
>
> Sub batman()
> For Each r In Selection
> s = Split(r.Value, " ")
> s(UBound(s)) = Chr(10) & s(UBound(s))
> r.Value = Join(s, " ")
> Next
> End Sub
>
> 1. replace the macro
> 2. select the cells
> 3. run the macro
>
> Post back if more modifications are needed.
> --
> Gary''s Student - gsnu2007i
>
> "NickTheBatMan" wrote:
> > Mm, either I've got the wrong end of this or it don't do what I was
> > hoping for...

>
> > It's putting Chr10 - a CR - at the beginning of the cell, or if I
> > select several cells it progresses to the next cell and puts the next
> > space in the text until it runs out of text then it fails...

>
> > Here's some of the text from the cells: -

>
> > WHITEHOUSE FPS-DSN2-015-1672
> > WEST DYKE ROAD MCG-DSN3-022-1562
> > CHURCH LANE CCTV-DSN3-023-0440
> > GREEN LANE FPS-DSN3-024-1100
> > GREW GRASS UWC-DSN3-025-0110

>
> > As you can see there's not equal words to begin with, I want the CR
> > before the group that is held together by the - hyphen...

>
> > Nick

>
> > On 26 May, 17:28, Gary''s Student
> > <GarysStud...@discussions.microsoft.com> wrote:
> > > Let's pick a cell and enter:

>
> > > go to alpha ralpha blvd

>
> > > If we select the cell and touch F2 and then CNTRL-BACKARROW three times, the
> > > editting cursor will be just before the alpha and this is where the Chr(10)
> > > will go. Try this simple macro:

>
> > > Sub batman()
> > > For Each r In Selection
> > > s = Split(r.Value, " ")
> > > s(UBound(s) - 2) = Chr(10) & s(UBound(s) - 2)
> > > r.Value = Join(s, " ")
> > > Next
> > > End Sub

>
> > > --
> > > Gary''s Student - gsnu2007i

>
> > > "NickTheBatMan" wrote:
> > > > I have a sheet of data where in column C I want to insert Chr10 in
> > > > each cell at the point where if I'm doing it manually I F2 to edit the
> > > > cell then Ctrl L Arrow thrice...

>
> > > > I've tried recording a Macro to do this but it just includes the text
> > > > of the particular cell that I'm currently editing and inserts the
> > > > Chr10 in where I have done it manually without telling me how to do
> > > > what I want....

>
> > > > I'd like to do it with a Macro as I've 1700ish rows to do and am
> > > > starting to get RSI from it :(

>
> > > > Eventually this will be saved as a CSV file so there'll be nothing
> > > > Excel in it...

>
> > > > Any help gratefully received :)

>
> > > > Nick


Weeeeeeeeeeeeee :) :) :)

Worked like a dream :) :) :)

Wish I could understand how to do all this clever stuff.........

VMT

Nick
Reply With Quote
  #7 (permalink)  
Old 05-26-2008, 10:21 PM
NickTheBatMan
 
Posts: n/a
Re: Can I make a Macro do the following for me ?

Many thanks for all that Rick, it doesn't matter about the space at
the end of the first line...

Didn't know about vblf, not sure if it's necessary as chr10's doing
what I want anyway... :)

For info all, this is me creating Points Of Interest layer for my
Garmin GPS so that I can upload it and it looks good on the device :)

It's worked so far...

Nick

On 26 May, 21:34, "Rick Rothstein \(MVP - VB\)"
<rick.newsNO.S...@NO.SPAMverizon.net> wrote:
> I'm not sure if it is important to the OP or not, but your routine leaves a
> trailing space at the end the first line formed by the split. I guess you
> could use the Replace function like this to remove the trailing space...
>
> Sub batman()
> Dim r As Range
> Dim s As Variant
> For Each r In Selection
> s = Split(r.Value, " ")
> s(UBound(s)) = Chr(10) & s(UBound(s))
> r.Value = Join(s, " ")
> r.Value = Replace(r.Value, " " & Chr(10), Chr(10))
> Next
> End Sub
>
> Here is an alternate subroutine which, as a by product of how it works, does
> not introduce the trailing space in the first place...
>
> Sub AddCR()
> Dim Cell As Range
> Dim Contents As String
> For Each Cell In Range("A1:A5")
> Contents = Cell.Text
> Mid$(Contents, InStrRev(Contents, " ")) = vbLf
> Cell.Value = Contents
> Next
> End Sub
>
> Note my preference for the predefined VB constant vbLf instead of the
> Chr(10) function call.
>
> Rick
>
> "Gary''s Student" <GarysStud...@discussions.microsoft.com> wrote in message
>
> news:AFD80B0E-9E5E-4E31-BF24-70BFD38FD84B@microsoft.com...
>
> > Have patience...we are making good progress. Your examples removed part
> > of
> > my confusion. We clearly do not need the -2

>
> > Try this new version instead:

>
> > Sub batman()
> > For Each r In Selection
> > s = Split(r.Value, " ")
> > s(UBound(s)) = Chr(10) & s(UBound(s))
> > r.Value = Join(s, " ")
> > Next
> > End Sub

>
> > 1. replace the macro
> > 2. select the cells
> > 3. run the macro

>
> > Post back if more modifications are needed.
> > --
> > Gary''s Student - gsnu2007i

>
> > "NickTheBatMan" wrote:

>
> >> Mm, either I've got the wrong end of this or it don't do what I was
> >> hoping for...

>
> >> It's putting Chr10 - a CR - at the beginning of the cell, or if I
> >> select several cells it progresses to the next cell and puts the next
> >> space in the text until it runs out of text then it fails...

>
> >> Here's some of the text from the cells: -

>
> >> WHITEHOUSE FPS-DSN2-015-1672
> >> WEST DYKE ROAD MCG-DSN3-022-1562
> >> CHURCH LANE CCTV-DSN3-023-0440
> >> GREEN LANE FPS-DSN3-024-1100
> >> GREW GRASS UWC-DSN3-025-0110

>
> >> As you can see there's not equal words to begin with, I want the CR
> >> before the group that is held together by the - hyphen...

>
> >> Nick

>
> >> On 26 May, 17:28, Gary''s Student
> >> <GarysStud...@discussions.microsoft.com> wrote:
> >> > Let's pick a cell and enter:

>
> >> > go to alpha ralpha blvd

>
> >> > If we select the cell and touch F2 and then CNTRL-BACKARROW three
> >> > times, the
> >> > editting cursor will be just before the alpha and this is where the
> >> > Chr(10)
> >> > will go. Try this simple macro:

>
> >> > Sub batman()
> >> > For Each r In Selection
> >> > s = Split(r.Value, " ")
> >> > s(UBound(s) - 2) = Chr(10) & s(UBound(s) - 2)
> >> > r.Value = Join(s, " ")
> >> > Next
> >> > End Sub

>
> >> > --
> >> > Gary''s Student - gsnu2007i

>
> >> > "NickTheBatMan" wrote:
> >> > > I have a sheet of data where in column C I want to insert Chr10 in
> >> > > each cell at the point where if I'm doing it manually I F2 to edit
> >> > > the
> >> > > cell then Ctrl L Arrow thrice...

>
> >> > > I've tried recording a Macro to do this but it just includes the text
> >> > > of the particular cell that I'm currently editing and inserts the
> >> > > Chr10 in where I have done it manually without telling me how to do
> >> > > what I want....

>
> >> > > I'd like to do it with a Macro as I've 1700ish rows to do and am
> >> > > starting to get RSI from it :(

>
> >> > > Eventually this will be saved as a CSV file so there'll be nothing
> >> > > Excel in it...

>
> >> > > Any help gratefully received :)

>
> >> > > Nick


Reply With Quote
Reply

  { mindfrost82.com } > Gadget Corner > Tech Newsgroups > Microsoft > MS Office > Excel


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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



All times are GMT. The time now is 03:38 AM.


Powered by vBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.
© 1999-2008 mindfrost82.com v11.0


Sponsors:
Credit Cards | Loans | Credit Cards | Debt Consolidation | Personal Car Finance



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114