Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 67
Default Find text and move it to other cell

Hi,

I have thousands of lines in a column, I need to find a text and move
it another column.

My data :

Col A

xxxx ABC1234 XXXX
xxxx ABC 1234 XXXx
xxxx ABC-1234 XXXx
xxxx ABC 1234a XXXx
xxxx ABC 1234ab XXXx
xxxx ABC-1234ab XXXx

What I need to find is the number and the last 1 or 2 character behind
it, such as 1234, 1234a or 1234ab and move it to column B.
ABC is fixed, but sometimes users put the space or "-" behind the ABC
and sometimes they use lower case.

I need the macro or the formula to figure it out, if possible.

Million of thanks.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Find text and move it to other cell

Hi Broogle,

Try:

Public Sub Tester001()

Dim rng As Range
Dim rCell As Range
Dim WB As Workbook
Dim SH As Worksheet
Dim CalcMode As Long
Const SearchString As String = "1234"

Set WB = ActiveWorkbook '<<========== CHANGE
Set SH = WB.Sheets("Sheet1") '<<========== CHANGE
Set rng = Intersect(SH.Columns(1), SH.UsedRange)

With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With

For Each rCell In rng.Cells
If InStr(1, rCell.Value, SearchString, vbTextCompare) 0 Then
rCell(1, 2) = rCell.Value
rCell.ClearContents
End If
Next rCell

With Application
.Calculation = CalcMode
.ScreenUpdating = True
End With

End Sub


---
Regards,
Norman



"broogle" wrote in message
oups.com...
Hi,

I have thousands of lines in a column, I need to find a text and move
it another column.

My data :

Col A

xxxx ABC1234 XXXX
xxxx ABC 1234 XXXx
xxxx ABC-1234 XXXx
xxxx ABC 1234a XXXx
xxxx ABC 1234ab XXXx
xxxx ABC-1234ab XXXx

What I need to find is the number and the last 1 or 2 character behind
it, such as 1234, 1234a or 1234ab and move it to column B.
ABC is fixed, but sometimes users put the space or "-" behind the ABC
and sometimes they use lower case.

I need the macro or the formula to figure it out, if possible.

Million of thanks.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 67
Default Find text and move it to other cell

Thanks Norman,

Forgot to mention that 1234 is a variable, it can be 4356 or 7654 or
7888a, 4321tr, 2344G, etc.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Find text and move it to other cell

Hi Broogle,

You report your base data as of the form:

xxxx ABC1234 XXXX
xxxx ABC 1234 XXXx
xxxx ABC-1234 XXXx
xxxx ABC 1234a XXXx
xxxx ABC 1234ab XXXx
xxxx ABC-1234ab XXXx


I understand that the 4-digit numeric string may vary.

However, what distinguishes the zero, 1 or 2 letter suffix to this numeric
string? Put another way, What are the XXX characters: numerics, upper case,
lower case or do they have a constant or special value


---
Regards,
Norman



"broogle" wrote in message
oups.com...
Thanks Norman,

Forgot to mention that 1234 is a variable, it can be 4356 or 7654 or
7888a, 4321tr, 2344G, etc.



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Find text and move it to other cell

Hi Broogle,

Try:

'==================
Public Sub Tester001()

Dim rng As Range
Dim rCell As Range
Dim wb As Workbook
Dim SH As Worksheet
Dim SStr As String
Dim CalcMode As Long
Const SearchString As String = "1234"

Set wb = ActiveWorkbook '<<========== CHANGE
Set SH = wb.Sheets("Sheet2") '<<========== CHANGE
Set rng = Intersect(SH.Columns(1), SH.UsedRange)

With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With

For Each rCell In rng.Cells
SStr = Mid(rCell.Value, 9)
SStr = Left(SStr, Len(SStr) - 5)
SStr = LTrim(SStr)
SStr = Replace(SStr, "-", "")
rCell(1, 2).Value = SStr
Next rCell

With Application
.Calculation = CalcMode
.ScreenUpdating = True
End With

End Sub
'==================

---
Regards,
Norman



"broogle" wrote in message
oups.com...
Thanks Norman,

Forgot to mention that 1234 is a variable, it can be 4356 or 7654 or
7888a, 4321tr, 2344G, etc.





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 67
Default Find text and move it to other cell

Hi Norman,

XXXX represent text, and the sufix are between a to z or A to Z.

i.e. "Building Maintenance Code BAS5644Na" or "Silo Materials Code
SIM7721" or "Maintenance on Progress Code MAT9021a", etc.

Thanks

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Find text and move it to other cell

Hi Broogle,

How does:

"Building Maintenance Code BAS5644Na"


correspond to your data format definition:

xxxx ABC1234


!!!

Try:

'===================
Public Sub Tester001()

Dim rng As Range
Dim rCell As Range
Dim wb As Workbook
Dim SH As Worksheet
Dim SStr As String
Dim Pos As Long
Dim CalcMode As Long
Const SearchString As String = "1234"

Set wb = ActiveWorkbook '<<========== CHANGE
Set SH = wb.Sheets("Sheet2") '<<========== CHANGE
Set rng = Intersect(SH.Columns(1), SH.UsedRange)

With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With

For Each rCell In rng.Cells
If Not IsEmpty(rCell.Value) Then
SStr = rCell.Value
Pos = InStr(1, SStr, "Code", vbTextCompare)
SStr = Mid(SStr, Pos + 8)
SStr = Left(SStr, Len(SStr) - 5)
SStr = LTrim(SStr)
SStr = Replace(SStr, "-", "")
rCell(1, 2).Value = SStr
End If
Next rCell

With Application
.Calculation = CalcMode
.ScreenUpdating = True
End With

End Sub

'<<===================


---
Regards,
Norman



"broogle" wrote in message
ps.com...
Hi Norman,

XXXX represent text, and the sufix are between a to z or A to Z.

i.e. "Building Maintenance Code BAS5644Na" or "Silo Materials Code
SIM7721" or "Maintenance on Progress Code MAT9021a", etc.

Thanks



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 46
Default Find text and move it to other cell

Can we chop the left (B1=right(A1, len(A1)-8))
then chop the right (C1=left(B1, len(B1)-5))
You can trim the space, but what do you want to do with the "-" please?

"broogle" wrote:

Hi,

I have thousands of lines in a column, I need to find a text and move
it another column.

My data :

Col A

xxxx ABC1234 XXXX
xxxx ABC 1234 XXXx
xxxx ABC-1234 XXXx
xxxx ABC 1234a XXXx
xxxx ABC 1234ab XXXx
xxxx ABC-1234ab XXXx

What I need to find is the number and the last 1 or 2 character behind
it, such as 1234, 1234a or 1234ab and move it to column B.
ABC is fixed, but sometimes users put the space or "-" behind the ABC
and sometimes they use lower case.

I need the macro or the formula to figure it out, if possible.

Million of thanks.


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
Excel 2007: mouse cant find cell handle to drag/move Carl Henthorn Excel Discussion (Misc queries) 4 April 30th 23 03:44 AM
Find text and move Johnny Excel Discussion (Misc queries) 7 November 28th 07 04:08 PM
find text and move it saman110 via OfficeKB.com Excel Discussion (Misc queries) 2 September 26th 07 08:25 PM
Find Matching Text In Col A move to Col B J.J. Excel Worksheet Functions 3 February 26th 06 04:53 AM
Find text and copy and move row containing it gjpcoach Excel Discussion (Misc queries) 5 February 24th 06 08:32 PM


All times are GMT +1. The time now is 09:54 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"