Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 88
Default How replace a character in a string of characters?

Anyone know how to pick out a digit in a string of characters like
this? =---FS- 12345 I am trying to replace the first character and
my code keeps coming back with "type mismatch error 13". My code is
simple (but wrong). I am trying to get rid of the = character and
replace it with a ' .

Thx
Chet

Sub REMOVE_INVALID_DATA_PHX_DOWNLOAD()

MaxRow = ActiveSheet.Range("A65536").End(xlUp).Row

For Rowy = 2 To MaxRow
Target = Left(Cells(Rowy, 11), 1)
If Target = "=" Then Target = "'"
Left(Cells(Rowy, 11), 1) = Target
Next Rowy

End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default How replace a character in a string of characters?

Hi Chet,
try this revised version

Sub REMOVE_INVALID_DATA_PHX_DOWNLOAD()

MaxRow = ActiveSheet.Range("A65536").End(xlUp).Row

For rowy = 2 To MaxRow
Target = Left(Cells(rowy, 11), 1)
If Target = "=" Then
Cells(rowy, 11) = Mid(Cells(rowy, 11), 2)
End If
Next rowy

End Sub

I think your code was failing because you can only use the LEFT
function for reading a value not for writing.

Cath

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 88
Default How replace a character in a string of characters?

Hi Cath,
Thanks for your help! I should have mentioned my code is failing at
the Target = Left(Cells(rowy, 11), 1) line. It still is failing at
that point. Any other ideas? :)

Thx Chet

wrote:
Hi Chet,
try this revised version

Sub REMOVE_INVALID_DATA_PHX_DOWNLOAD()

MaxRow = ActiveSheet.Range("A65536").End(xlUp).Row

For rowy = 2 To MaxRow
Target = Left(Cells(rowy, 11), 1)
If Target = "=" Then
Cells(rowy, 11) = Mid(Cells(rowy, 11), 2)
End If
Next rowy

End Sub

I think your code was failing because you can only use the LEFT
function for reading a value not for writing.

Cath


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default How replace a character in a string of characters?

Chet,
AH! it seems your cells that start with = do really contain formulae.
I had assumed there was a quote before the = to make them strings. In
which case try this.

Sub REMOVE_INVALID_DATA_PHX_DOWNLOAD()
Dim Target As String

MaxRow = ActiveSheet.Range("A65536").End(xlUp).Row

For rowy = 2 To MaxRow
Target = Cells(rowy, 11).Formula
If Left(Target, 1) = "=" Then
Cells(rowy, 11) = Mid(Target, 2)
End If
Next rowy


End Sub

Cath

  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 140
Default How replace a character in a string of characters?

Hi

You could try this. It will remove the = sign and replace with the '
text symbol.

However this results in the formula appearing in the cell ie 'A2+B2 not
the whole number. If this is what you want this should do the trick.

Sub Remove()

Dim StartRng As Range
Set StartRng = Range("a1", Range("A65536").End(xlUp))

For Each cell In StartRng
StartRng.Replace what:="=", Replacement:="'", LookAt:=xlPart
Next

End Sub

wrote:
Chet,
AH! it seems your cells that start with = do really contain formulae.
I had assumed there was a quote before the = to make them strings. In
which case try this.

Sub REMOVE_INVALID_DATA_PHX_DOWNLOAD()
Dim Target As String

MaxRow = ActiveSheet.Range("A65536").End(xlUp).Row

For rowy = 2 To MaxRow
Target = Cells(rowy, 11).Formula
If Left(Target, 1) = "=" Then
Cells(rowy, 11) = Mid(Target, 2)
End If
Next rowy


End Sub

Cath


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default How replace a character in a string of characters?

Chet,
Not sure if you actually have a formula or text in your cells, but...
The default property of a Range is .Value. So that is what you are working
with here, as you do not specify a property in your code.
There is also the .Formula and .HasFormula which may be what you need
instead, if formulae are involved.

For Rowy = 2 To MaxRow
with Cells(Rowy, 11)
If .HasFormula = True Then .value = "'" & .formula
end with
Next Rowy

NickHK

"Chet" wrote in message
oups.com...
Anyone know how to pick out a digit in a string of characters like
this? =---FS- 12345 I am trying to replace the first character and
my code keeps coming back with "type mismatch error 13". My code is
simple (but wrong). I am trying to get rid of the = character and
replace it with a ' .

Thx
Chet

Sub REMOVE_INVALID_DATA_PHX_DOWNLOAD()

MaxRow = ActiveSheet.Range("A65536").End(xlUp).Row

For Rowy = 2 To MaxRow
Target = Left(Cells(Rowy, 11), 1)
If Target = "=" Then Target = "'"
Left(Cells(Rowy, 11), 1) = Target
Next Rowy

End Sub



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
Replace character in string, not document KS[_2_] Excel Programming 3 October 26th 06 05:06 PM
Extracting a character from a string of characters Sue Excel Discussion (Misc queries) 6 October 30th 05 01:35 AM
Remove all characters following the first character in a string RC Excel Discussion (Misc queries) 5 August 30th 05 03:17 AM
want to remove all text characters equal to one character in length from text string [email protected] Excel Worksheet Functions 1 April 18th 05 12:25 AM
How do I replace * as a character in a string in Excel? nicolegt Excel Programming 1 January 21st 05 10:42 AM


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