PC Review


Reply
Thread Tools Rate Thread

how to choose a part of the text in a cell???

 
 
Ksenija
Guest
Posts: n/a
 
      30th Nov 2009
Can someone help me? If I have a text saying "AAAAA_BBBBB" in a cell, how can
I write a code that copies the text in front of "_" and pastes it in a cell
above????

So I have "AAAAA_BBBBB" and want to have AAAAA pasted in a cell above..
 
Reply With Quote
 
 
 
 
Jacob Skaria
Guest
Posts: n/a
 
      30th Nov 2009
If you are looking for a fomula try the below
=LEFT(A1,FIND("_",A1)-1)

If you are looking for a VBA code; try

Split(Range("A1"),"_")(0)

or

Dim strData as String
strData = "AAAAA_BBBBB"
Msgbox Split(strData,"_")(0)

"Ksenija" wrote:

> Can someone help me? If I have a text saying "AAAAA_BBBBB" in a cell, how can
> I write a code that copies the text in front of "_" and pastes it in a cell
> above????
>
> So I have "AAAAA_BBBBB" and want to have AAAAA pasted in a cell above..

 
Reply With Quote
 
Ksenija
Guest
Posts: n/a
 
      30th Nov 2009
Hi again,
sorry, I can't make it work...

the thing is, I am trying to put this in a loop så it goes thrue a lot of
cells, så I can't specify which exact cell I am in (A1 etc)..

so I don't really knom how to make

Split(Range("A1"),"_")(0),

work...



"Jacob Skaria" wrote:

> If you are looking for a fomula try the below
> =LEFT(A1,FIND("_",A1)-1)
>
> If you are looking for a VBA code; try
>
> Split(Range("A1"),"_")(0)
>
> or
>
> Dim strData as String
> strData = "AAAAA_BBBBB"
> Msgbox Split(strData,"_")(0)
>
> "Ksenija" wrote:
>
> > Can someone help me? If I have a text saying "AAAAA_BBBBB" in a cell, how can
> > I write a code that copies the text in front of "_" and pastes it in a cell
> > above????
> >
> > So I have "AAAAA_BBBBB" and want to have AAAAA pasted in a cell above..

 
Reply With Quote
 
Rick Rothstein
Guest
Posts: n/a
 
      30th Nov 2009
It would really help us if you posted the code you have so we can see how to
integrate this into it.

--
Rick (MVP - Excel)


"Ksenija" <(E-Mail Removed)> wrote in message
news:2D08B52B-93D0-4C79-BD48-(E-Mail Removed)...
> Hi again,
> sorry, I can't make it work...
>
> the thing is, I am trying to put this in a loop så it goes thrue a lot of
> cells, så I can't specify which exact cell I am in (A1 etc)..
>
> so I don't really knom how to make
>
> Split(Range("A1"),"_")(0),
>
> work...
>
>
>
> "Jacob Skaria" wrote:
>
>> If you are looking for a fomula try the below
>> =LEFT(A1,FIND("_",A1)-1)
>>
>> If you are looking for a VBA code; try
>>
>> Split(Range("A1"),"_")(0)
>>
>> or
>>
>> Dim strData as String
>> strData = "AAAAA_BBBBB"
>> Msgbox Split(strData,"_")(0)
>>
>> "Ksenija" wrote:
>>
>> > Can someone help me? If I have a text saying "AAAAA_BBBBB" in a cell,
>> > how can
>> > I write a code that copies the text in front of "_" and pastes it in a
>> > cell
>> > above????
>> >
>> > So I have "AAAAA_BBBBB" and want to have AAAAA pasted in a cell above..


 
Reply With Quote
 
fisch4bill
Guest
Posts: n/a
 
      30th Nov 2009
Hi, assuming that your data is in A2: ??2 and that you want it pasted in A1:
??1, try the following (adjusted to fit your data's location):

Sub TextSplit()
Dim Cell As Range
For Each Cell In Range("A2:" & Cells(2, Columns.Count).End(xlToLeft).Address)
Cell.Offset(-1, 0).Value = Split(Cell.Value, "_")(0)
Next Cell
End Sub

Hope this helps, but without seeing more detail (your code would be helpful)
I can't be more specific. This code will select just the data to the left of
the "_". If you want the data to the right ("BBBBB" from "AAAAA_BBBBB") then
substitute a 1 for the 0.


"Ksenija" wrote:

> Hi again,
> sorry, I can't make it work...
>
> the thing is, I am trying to put this in a loop så it goes thrue a lot of
> cells, så I can't specify which exact cell I am in (A1 etc)..
>
> so I don't really knom how to make
>
> Split(Range("A1"),"_")(0),
>
> work...
>
>
>
> "Jacob Skaria" wrote:
>
> > If you are looking for a fomula try the below
> > =LEFT(A1,FIND("_",A1)-1)
> >
> > If you are looking for a VBA code; try
> >
> > Split(Range("A1"),"_")(0)
> >
> > or
> >
> > Dim strData as String
> > strData = "AAAAA_BBBBB"
> > Msgbox Split(strData,"_")(0)
> >
> > "Ksenija" wrote:
> >
> > > Can someone help me? If I have a text saying "AAAAA_BBBBB" in a cell, how can
> > > I write a code that copies the text in front of "_" and pastes it in a cell
> > > above????
> > >
> > > So I have "AAAAA_BBBBB" and want to have AAAAA pasted in a cell above..

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
how can I choose part of the text in a cell and paste it elsewhere Ksenija Microsoft Access VBA Modules 1 30th Nov 2009 01:59 PM
how to cut part of a text from one cell and automatically paste itonto another cell Sonja Microsoft Excel Misc 6 17th Aug 2009 11:35 PM
choose a cell in a range which has a text (there is only one) flying man Microsoft Excel Misc 2 6th Feb 2009 03:43 PM
copy selected part number of text from one cell into another cell orewa Microsoft Excel Misc 1 11th Apr 2008 01:30 PM
Display contents of cell in another cell as part of text string? mschmidt@carolina.rr.com Microsoft Excel New Users 3 8th Jul 2006 07:44 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:26 AM.