Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Conditional replace

I am looking to search one column for "V" in a string.

When there is a letter preceding the "V" I need to add "-" between the
letter and the "V".
When there is a number preceding the "V" then I need it to leave it like it
is.

Results need to look like this.

old new
1MSV01 1MS-V01
1MS4V01 1MS4V01

Anyone have any ideas how I could do this quickly. I have several sheets
with several thousand records each.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 644
Default Conditional replace

Ctrl+H
Find What = "V"
Replace With = "-V"
Expand options
Within = Workbook
Match Case = True

Click "Replace All"

Charles Chickering
Mikey B wrote:
I am looking to search one column for "V" in a string.

When there is a letter preceding the "V" I need to add "-" between the
letter and the "V".
When there is a number preceding the "V" then I need it to leave it like it
is.

Results need to look like this.

old new
1MSV01 1MS-V01
1MS4V01 1MS4V01

Anyone have any ideas how I could do this quickly. I have several sheets
with several thousand records each.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Conditional replace

Ok, thanks for your reply but it does not actually do what I was looking for.
The reason why I did not use the normal find/replace is that this results in
adding a dash in front of the "V" in all cases including when numbers precede
the "V" which is what I am trying to avoid.
I thought there might have been a way to do this programatically using a
if...then statement.

Also, in some cases the dash is already already correctly in place and
adding another dash would not be wanted.

I appreciate any help.

"Die_Another_Day" wrote:

Ctrl+H
Find What = "V"
Replace With = "-V"
Expand options
Within = Workbook
Match Case = True

Click "Replace All"

Charles Chickering
Mikey B wrote:
I am looking to search one column for "V" in a string.

When there is a letter preceding the "V" I need to add "-" between the
letter and the "V".
When there is a number preceding the "V" then I need it to leave it like it
is.

Results need to look like this.

old new
1MSV01 1MS-V01
1MS4V01 1MS4V01

Anyone have any ideas how I could do this quickly. I have several sheets
with several thousand records each.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 644
Default Conditional replace

Try this subroutine.
Sub ReplaceAll()
Dim cnt As Long
Dim Vpos As Long 'V position
Dim CrCl As Range 'Current Cell
Dim WS As Worksheet
Const Cmn As String = "A"
For Each WS In ActiveWorkbook.Sheets
For cnt = 1 To WS.Range(Cmn & Rows.Count).End(xlUp).Row
Set CrCl = WS.Range(Cmn & cnt)
Vpos = InStr(1, CrCl, "V")
If Vpos 0 Then
If Not IsNumeric(Mid(CrCl, Vpos - 1, 1)) Then
CrCl.Value = Left(CrCl, Vpos - 1) & "-" & _
Right(CrCl, Len(CrCl) - Vpos + 1)
End If
End If
Next
Next
End Sub

Charles

Mikey B wrote:
Ok, thanks for your reply but it does not actually do what I was looking for.
The reason why I did not use the normal find/replace is that this results in
adding a dash in front of the "V" in all cases including when numbers precede
the "V" which is what I am trying to avoid.
I thought there might have been a way to do this programatically using a
if...then statement.

Also, in some cases the dash is already already correctly in place and
adding another dash would not be wanted.

I appreciate any help.

"Die_Another_Day" wrote:

Ctrl+H
Find What = "V"
Replace With = "-V"
Expand options
Within = Workbook
Match Case = True

Click "Replace All"

Charles Chickering
Mikey B wrote:
I am looking to search one column for "V" in a string.

When there is a letter preceding the "V" I need to add "-" between the
letter and the "V".
When there is a number preceding the "V" then I need it to leave it like it
is.

Results need to look like this.

old new
1MSV01 1MS-V01
1MS4V01 1MS4V01

Anyone have any ideas how I could do this quickly. I have several sheets
with several thousand records each.




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Conditional replace

Thanks Charles. This works great.

"Die_Another_Day" wrote:

Try this subroutine.
Sub ReplaceAll()
Dim cnt As Long
Dim Vpos As Long 'V position
Dim CrCl As Range 'Current Cell
Dim WS As Worksheet
Const Cmn As String = "A"
For Each WS In ActiveWorkbook.Sheets
For cnt = 1 To WS.Range(Cmn & Rows.Count).End(xlUp).Row
Set CrCl = WS.Range(Cmn & cnt)
Vpos = InStr(1, CrCl, "V")
If Vpos 0 Then
If Not IsNumeric(Mid(CrCl, Vpos - 1, 1)) Then
CrCl.Value = Left(CrCl, Vpos - 1) & "-" & _
Right(CrCl, Len(CrCl) - Vpos + 1)
End If
End If
Next
Next
End Sub

Charles

Mikey B wrote:
Ok, thanks for your reply but it does not actually do what I was looking for.
The reason why I did not use the normal find/replace is that this results in
adding a dash in front of the "V" in all cases including when numbers precede
the "V" which is what I am trying to avoid.
I thought there might have been a way to do this programatically using a
if...then statement.

Also, in some cases the dash is already already correctly in place and
adding another dash would not be wanted.

I appreciate any help.

"Die_Another_Day" wrote:

Ctrl+H
Find What = "V"
Replace With = "-V"
Expand options
Within = Workbook
Match Case = True

Click "Replace All"

Charles Chickering
Mikey B wrote:
I am looking to search one column for "V" in a string.

When there is a letter preceding the "V" I need to add "-" between the
letter and the "V".
When there is a number preceding the "V" then I need it to leave it like it
is.

Results need to look like this.

old new
1MSV01 1MS-V01
1MS4V01 1MS4V01

Anyone have any ideas how I could do this quickly. I have several sheets
with several thousand records each.




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
Conditional Replace without macros Craig Excel Worksheet Functions 2 May 20th 09 11:34 PM
Conditional FIND and REPLACE wisynco Excel Worksheet Functions 0 June 7th 06 06:46 PM
Create a conditional formula to replace dot Excel Worksheet Functions 2 April 24th 06 01:35 PM
Is it possible to do a Find/Replace on Conditional Formats? [email protected] Excel Worksheet Functions 2 October 21st 05 01:33 PM
Replace conditional formatting to use 4 conditions Rob[_22_] Excel Programming 3 September 23rd 04 07:20 PM


All times are GMT +1. The time now is 09:14 PM.

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

About Us

"It's about Microsoft Excel"