LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #18   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default Changing text order into a cell

On Sun, 28 Sep 2008 01:48:11 -0700, Daniel Thuriaux wrote:

Hello,

Can somebody help me with the following?

I'm using Excel (office 2007)

I have to manage pricelists containing each abt.5000 rows
Unfortunately, the information in the cells of the Column C appears in the wrong order

for example, the existing format is:

A B C
BRAND Item BRAND Description ITEM

I would like to invert the content of the cells in the column C into:

A B C
BRAND Item BRAND ITEM Description

I already did a try with a macro clearing partly the text equal to the text found in the colomn A and B, but I haven’t found a way to insert it back into the cells of the column C in the right order
Is there a possibility to have it done with a macro?

Thanks in advance for your help


Perhaps this will work. Be sure to read the comments within the Sub:

===========================================
Option Explicit
Sub ChangeOrder()
Dim c As Range
Dim rg As Range
Dim sRes(0 To 2) As String
Dim sDesc As String
Dim i As Long

Set rg = Range("A1:A5000") 'set to range to be processed
' first column only
For Each c In rg
sRes(0) = Trim(c.Value) 'BRAND
sRes(1) = Trim(c.Offset(0, 1).Value) 'Item
sRes(2) = Trim(c.Offset(0, 2).Value) 'original
'remove BRAND
sRes(2) = Replace(sRes(2), sRes(0), "", 1, 1, vbTextCompare)
'check for duplicate of Item value
i = Len(sRes(2)) - Len(Replace(sRes(2), sRes(1), "", , , vbTextCompare))
'replace "last" item value
sRes(2) = Replace(sRes(2), sRes(1), "", 1, i, vbTextCompare)
'column offset set to 3 for debugging. When satisfied, set it to 2
c.Offset(0, 3).Value = Join(sRes)
Next c
End Sub
====================================
--ron
 
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
Adding Zeros in front of numbers in cells using Excel 2003 jfcby[_2_] Excel Programming 14 September 28th 06 02:31 PM
HowTo add a period to front of EVERY text cell in a Excel column adamcollegeman Excel Programming 4 November 24th 05 07:51 AM
input text at front of field that contains data Steve M Excel Discussion (Misc queries) 3 May 16th 05 12:28 AM
Formula for adding a comma in front of text in a cell Shelley Excel Worksheet Functions 4 April 18th 05 04:34 PM
How do I Remove bullets from text data in Excel cell with macro? David McRitchie Excel Programming 0 September 19th 04 09:22 PM


All times are GMT +1. The time now is 10:02 AM.

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"