Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 36
Default Retry - Find and Replace Macro

Hi,
(XL 2002, Win XP--VB Newbie)

I have in cells
A1 = mm97z.60
B1 = mm97z.15
C1 = mm97z.5
etc...

I need to create a macro that will look for the first digits it encouters in
the cells and replace then with same digits but +1 (e.g. the 97 in cell
A1 --mm97z.60 would turn into 98 with result mm98z.60.

After reaching 99, it needs to continue not as 100, 101, etc., but as 00,
01, etc.

This needs to be done for a range of cells that are always in Column A but
with various possible lengths which I usually select manually with
Control\End Down Arrow.

Tx for the suggestions.
S


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 599
Default Retry - Find and Replace Macro

S

Try this

Sub Add1()

Dim cell As Range
Dim Rng As Range
Dim i As Long
Dim lVal As Long
Dim sNew As String

Set Rng = Sheet1.Range("A1", _
Sheet1.Range("A" & Sheet1.Rows.Count).End(xlUp))

For Each cell In Rng.Cells
For i = 1 To Len(cell.Value)
If IsNumeric(Mid(cell.Value, i, 2)) Then
lVal = Val(Mid(cell.Value, i, 2))
sNew = Left(cell.Value, i - 1)
If lVal = 99 Then
lVal = 0
Else
lVal = lVal + 1
End If
sNew = sNew & Format(lVal, "00")
sNew = sNew & Right(cell.Value, Len(cell.Value) - i - 1)
cell.Value = sNew
Exit For
End If
Next i
Next cell

End Sub

--
Dick Kusleika
MVP - Excel
Excel Blog - Daily Dose of Excel
www.dicks-blog.com

"saturnin02" <saturnin02_at_hotmail.com wrote in message
...
Hi,
(XL 2002, Win XP--VB Newbie)

I have in cells
A1 = mm97z.60
B1 = mm97z.15
C1 = mm97z.5
etc...

I need to create a macro that will look for the first digits it encouters

in
the cells and replace then with same digits but +1 (e.g. the 97 in cell
A1 --mm97z.60 would turn into 98 with result mm98z.60.

After reaching 99, it needs to continue not as 100, 101, etc., but as 00,
01, etc.

This needs to be done for a range of cells that are always in Column A but
with various possible lengths which I usually select manually with
Control\End Down Arrow.

Tx for the suggestions.
S




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 36
Default Retry - Find and Replace Macro

You're the best Dick.
Works like a charm!
It will save me loads of time.
Tx a lot!
S


"Dick Kusleika" wrote in message
...
S

Try this

Sub Add1()

Dim cell As Range
Dim Rng As Range
Dim i As Long
Dim lVal As Long
Dim sNew As String

Set Rng = Sheet1.Range("A1", _
Sheet1.Range("A" & Sheet1.Rows.Count).End(xlUp))

For Each cell In Rng.Cells
For i = 1 To Len(cell.Value)
If IsNumeric(Mid(cell.Value, i, 2)) Then
lVal = Val(Mid(cell.Value, i, 2))
sNew = Left(cell.Value, i - 1)
If lVal = 99 Then
lVal = 0
Else
lVal = lVal + 1
End If
sNew = sNew & Format(lVal, "00")
sNew = sNew & Right(cell.Value, Len(cell.Value) - i - 1)
cell.Value = sNew
Exit For
End If
Next i
Next cell

End Sub

--
Dick Kusleika
MVP - Excel
Excel Blog - Daily Dose of Excel
www.dicks-blog.com

"saturnin02" <saturnin02_at_hotmail.com wrote in message
...
Hi,
(XL 2002, Win XP--VB Newbie)

I have in cells
A1 = mm97z.60
B1 = mm97z.15
C1 = mm97z.5
etc...

I need to create a macro that will look for the first digits it

encouters
in
the cells and replace then with same digits but +1 (e.g. the 97 in cell
A1 --mm97z.60 would turn into 98 with result mm98z.60.

After reaching 99, it needs to continue not as 100, 101, etc., but as

00,
01, etc.

This needs to be done for a range of cells that are always in Column A

but
with various possible lengths which I usually select manually with
Control\End Down Arrow.

Tx for the suggestions.
S






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 36
Default Retry - Find and Replace Macro

Dick,
I copied and pasted it in a test workbook and it worked great.
I then opened the "target" workbook did the same procedure, open VB Editor,
Add Module and Copy and pasted the code in it and NOTHING happens at all.
I cannot figure it out.
Here is how it appears in the VB Editor:

Sub Add1()

Dim cell As Range
Dim Rng As Range
Dim i As Long
Dim lVal As Long
Dim sNew As String

Set Rng = Sheet1.Range("A1", _
Sheet1.Range("A" & Sheet1.Rows.Count).End(xlUp))

For Each cell In Rng.Cells
For i = 1 To Len(cell.Value)
If IsNumeric(Mid(cell.Value, i, 2)) Then
lVal = Val(Mid(cell.Value, i, 2))
sNew = Left(cell.Value, i - 1)
If lVal = 99 Then
lVal = 0
Else
lVal = lVal + 1
End If
sNew = sNew & Format(lVal, "00")
sNew = sNew & Right(cell.Value, Len(cell.Value) - i - 1)
cell.Value = sNew
Exit For
End If
Next i
Next cell

End Sub

Am I missing something...?
S

"Dick Kusleika" wrote in message
...
S

Try this

Sub Add1()

Dim cell As Range
Dim Rng As Range
Dim i As Long
Dim lVal As Long
Dim sNew As String

Set Rng = Sheet1.Range("A1", _
Sheet1.Range("A" & Sheet1.Rows.Count).End(xlUp))

For Each cell In Rng.Cells
For i = 1 To Len(cell.Value)
If IsNumeric(Mid(cell.Value, i, 2)) Then
lVal = Val(Mid(cell.Value, i, 2))
sNew = Left(cell.Value, i - 1)
If lVal = 99 Then
lVal = 0
Else
lVal = lVal + 1
End If
sNew = sNew & Format(lVal, "00")
sNew = sNew & Right(cell.Value, Len(cell.Value) - i - 1)
cell.Value = sNew
Exit For
End If
Next i
Next cell

End Sub

--
Dick Kusleika
MVP - Excel
Excel Blog - Daily Dose of Excel
www.dicks-blog.com

"saturnin02" <saturnin02_at_hotmail.com wrote in message
...
Hi,
(XL 2002, Win XP--VB Newbie)

I have in cells
A1 = mm97z.60
B1 = mm97z.15
C1 = mm97z.5
etc...

I need to create a macro that will look for the first digits it

encouters
in
the cells and replace then with same digits but +1 (e.g. the 97 in cell
A1 --mm97z.60 would turn into 98 with result mm98z.60.

After reaching 99, it needs to continue not as 100, 101, etc., but as

00,
01, etc.

This needs to be done for a range of cells that are always in Column A

but
with various possible lengths which I usually select manually with
Control\End Down Arrow.

Tx for the suggestions.
S






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 36
Default Retry - Find and Replace Macro

Dick, I think I know why.
In the target workbook, the find and replace is not in Sheet 1 but changes
as number of sheets are added.
I guess I need to modify the macro and replace where it says sheet1 to ...is
it Active Window or something similar...?
Tx,
S
"Dick Kusleika" wrote in message
...
S

Try this

Sub Add1()

Dim cell As Range
Dim Rng As Range
Dim i As Long
Dim lVal As Long
Dim sNew As String

Set Rng = Sheet1.Range("A1", _
Sheet1.Range("A" & Sheet1.Rows.Count).End(xlUp))

For Each cell In Rng.Cells
For i = 1 To Len(cell.Value)
If IsNumeric(Mid(cell.Value, i, 2)) Then
lVal = Val(Mid(cell.Value, i, 2))
sNew = Left(cell.Value, i - 1)
If lVal = 99 Then
lVal = 0
Else
lVal = lVal + 1
End If
sNew = sNew & Format(lVal, "00")
sNew = sNew & Right(cell.Value, Len(cell.Value) - i - 1)
cell.Value = sNew
Exit For
End If
Next i
Next cell

End Sub

--
Dick Kusleika
MVP - Excel
Excel Blog - Daily Dose of Excel
www.dicks-blog.com

"saturnin02" <saturnin02_at_hotmail.com wrote in message
...
Hi,
(XL 2002, Win XP--VB Newbie)

I have in cells
A1 = mm97z.60
B1 = mm97z.15
C1 = mm97z.5
etc...

I need to create a macro that will look for the first digits it

encouters
in
the cells and replace then with same digits but +1 (e.g. the 97 in cell
A1 --mm97z.60 would turn into 98 with result mm98z.60.

After reaching 99, it needs to continue not as 100, 101, etc., but as

00,
01, etc.

This needs to be done for a range of cells that are always in Column A

but
with various possible lengths which I usually select manually with
Control\End Down Arrow.

Tx for the suggestions.
S








  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 36
Default Retry - Find and Replace Macro

Dick,
This is what I did:
(seems to work--let me know if I did it right or not)--I changed Sheet1 with
ActiveSheet)

Sub Add2()

Dim cell As Range
Dim Rng As Range
Dim i As Long
Dim lVal As Long
Dim sNew As String

Set Rng = ActiveSheet.Range("A1", _
ActiveSheet.Range("A" & ActiveSheet.Rows.Count).End(xlUp))

For Each cell In Rng.Cells
For i = 1 To Len(cell.Value)
If IsNumeric(Mid(cell.Value, i, 2)) Then
lVal = Val(Mid(cell.Value, i, 2))
sNew = Left(cell.Value, i - 1)
If lVal = 99 Then
lVal = 0
Else
lVal = lVal + 1
End If
sNew = sNew & Format(lVal, "00")
sNew = sNew & Right(cell.Value, Len(cell.Value) - i - 1)
cell.Value = sNew
Exit For
End If
Next i
Next cell

End Sub

"Dick Kusleika" wrote in message
...
S

Try this

Sub Add1()

Dim cell As Range
Dim Rng As Range
Dim i As Long
Dim lVal As Long
Dim sNew As String

Set Rng = Sheet1.Range("A1", _
Sheet1.Range("A" & Sheet1.Rows.Count).End(xlUp))

For Each cell In Rng.Cells
For i = 1 To Len(cell.Value)
If IsNumeric(Mid(cell.Value, i, 2)) Then
lVal = Val(Mid(cell.Value, i, 2))
sNew = Left(cell.Value, i - 1)
If lVal = 99 Then
lVal = 0
Else
lVal = lVal + 1
End If
sNew = sNew & Format(lVal, "00")
sNew = sNew & Right(cell.Value, Len(cell.Value) - i - 1)
cell.Value = sNew
Exit For
End If
Next i
Next cell

End Sub

--
Dick Kusleika
MVP - Excel
Excel Blog - Daily Dose of Excel
www.dicks-blog.com

"saturnin02" <saturnin02_at_hotmail.com wrote in message
...
Hi,
(XL 2002, Win XP--VB Newbie)

I have in cells
A1 = mm97z.60
B1 = mm97z.15
C1 = mm97z.5
etc...

I need to create a macro that will look for the first digits it

encouters
in
the cells and replace then with same digits but +1 (e.g. the 97 in cell
A1 --mm97z.60 would turn into 98 with result mm98z.60.

After reaching 99, it needs to continue not as 100, 101, etc., but as

00,
01, etc.

This needs to be done for a range of cells that are always in Column A

but
with various possible lengths which I usually select manually with
Control\End Down Arrow.

Tx for the suggestions.
S






  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 599
Default Retry - Find and Replace Macro


This is what I did:
(seems to work--let me know if I did it right or not)--I changed Sheet1

with
ActiveSheet)


Looks good to me. The important thing is that it works.


--
Dick Kusleika
MVP - Excel
Excel Blog - Daily Dose of Excel
www.dicks-blog.com


  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 36
Default Retry - Find and Replace Macro

Thanks a lot for your help.
S
"Dick Kusleika" wrote in message
...

This is what I did:
(seems to work--let me know if I did it right or not)--I changed Sheet1

with
ActiveSheet)


Looks good to me. The important thing is that it works.


--
Dick Kusleika
MVP - Excel
Excel Blog - Daily Dose of Excel
www.dicks-blog.com




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
Macro to Find and Replace R Storey Excel Discussion (Misc queries) 6 December 6th 06 07:04 PM
Macro: Find and replace Bertie Excel Discussion (Misc queries) 1 May 29th 06 02:01 PM
find&replace macro Elainey Excel Worksheet Functions 0 January 6th 06 09:20 PM
A Macro to Do Find and Replace Eric Excel Programming 2 February 27th 04 12:22 AM
Using Find & Replace in macro Bob C[_3_] Excel Programming 11 October 30th 03 07:02 PM


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