Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Splitting a cell in a macro?

I have a column of cells that I would like to be able to split
automatically the problem is that there are two possible choices. The
cells begin with either Plan A or Plan B. I need to split Plan A
after 17 characters and Plan B after 25 characters.

Is there a way to write a bit of code that would be able to
differentiate Plan A and Plan B in Column C and split them so that
Plan A and Plan B stay in Column C but the other bit...0/7 or 30/30
moves into column D?

Thanks for any help in advance.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Splitting a cell in a macro?

Mary,

You could try something like the macro below. I've assumed that your data in column C starts in row
2.

HTH,
Bernie
MS Excel MVP

Sub MarySplit()
Dim myRow As Long

myRow = Cells(Rows.Count, 3).End(xlUp).Row

Columns("D:E").Insert Shift:=xlToRight
Range("D2:D" & myRow).FormulaR1C1 = _
"=IF(LEFT(RC[-1],6)=""Plan A"",LEFT(RC[-1],17),LEFT(RC[-1],25))"
Range("E2:E" & myRow).FormulaR1C1 = "=SUBSTITUTE(RC[-2],RC[-1],"""")"
Range("D2:E" & myRow).Value = Range("D2:E" & myRow).Value
Columns("C:C").Delete Shift:=xlToLeft
Columns("C:D").EntireColumn.AutoFit
End Sub


"Dagonini" wrote in message
oups.com...
I have a column of cells that I would like to be able to split
automatically the problem is that there are two possible choices. The
cells begin with either Plan A or Plan B. I need to split Plan A
after 17 characters and Plan B after 25 characters.

Is there a way to write a bit of code that would be able to
differentiate Plan A and Plan B in Column C and split them so that
Plan A and Plan B stay in Column C but the other bit...0/7 or 30/30
moves into column D?

Thanks for any help in advance.



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
E2007 - Macro for splitting text and then replacing something Niniel Excel Discussion (Misc queries) 2 November 18th 09 10:11 AM
Macro Assistance (Splitting into new workbook by value) Dedrie Excel Discussion (Misc queries) 1 August 21st 09 08:31 PM
splitting cell text using macro Garrystone Excel Discussion (Misc queries) 3 February 1st 08 03:22 PM
Macro for splitting a cell Brian Brandt Excel Programming 4 June 2nd 06 10:19 AM
Splitting text in cell with Excel 97 VBA macro Vsevolod Excel Programming 3 May 11th 04 01:17 PM


All times are GMT +1. The time now is 10:03 PM.

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

About Us

"It's about Microsoft Excel"