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

In XL2000, I use the following sub to update some stuff each month, but the
Replace portion doesn't replace anything :(

Cells B42 and G42 contain formulas that link to cells in 'Foodcost.xls'

No errors occur, but it's probably some simple syntax problem I can't
solve.

Any help?

Sub Renew()
Dim OldMonth As String
Dim NewMonth As String
Dim wkbk As Workbook
Set wkbk = ActiveWorkbook
Application.ScreenUpdating = False
Workbooks.Open "Foodcost.xls"
wkbk.Activate
Range("Initial_Qty").Value = Range("On_Hand").Value
Range("Added_Used").ClearContents
OldMonth = Workbooks("Foodcost.xls").Sheets(5).Name 'i.e. Dec
NewMonth = Workbooks("Foodcost.xls").Sheets(6).Name 'i.e. Jan
Range("B42,G42").Cells.Replace What:=OldMonth, Replacement:=NewMonth,
LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False
Workbooks("Foodcost.xls").Close
Application.ScreenUpdating = True
End Sub

--
David
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default replace doesn't

David,

Did you mean for this to be all of the columns from B to
G in Row 42?

Try "B42:G42" rather than "B42,G42"

-Donna

-----Original Message-----
In XL2000, I use the following sub to update some stuff

each month, but the
Replace portion doesn't replace anything :(

Cells B42 and G42 contain formulas that link to cells

in 'Foodcost.xls'

No errors occur, but it's probably some simple syntax

problem I can't
solve.

Any help?

Sub Renew()
Dim OldMonth As String
Dim NewMonth As String
Dim wkbk As Workbook
Set wkbk = ActiveWorkbook
Application.ScreenUpdating = False
Workbooks.Open "Foodcost.xls"
wkbk.Activate
Range("Initial_Qty").Value = Range("On_Hand").Value
Range("Added_Used").ClearContents
OldMonth = Workbooks("Foodcost.xls").Sheets

(5).Name 'i.e. Dec
NewMonth = Workbooks("Foodcost.xls").Sheets

(6).Name 'i.e. Jan
Range("B42,G42").Cells.Replace What:=OldMonth,

Replacement:=NewMonth,
LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False
Workbooks("Foodcost.xls").Close
Application.ScreenUpdating = True
End Sub

--
David
.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 195
Default replace doesn't

Sharqua wrote

Did you mean for this to be all of the columns from B to
G in Row 42?


No. I only wanted to look at two cells (B42 and G42)... however:

Range("B42,G42").Cells.Replace What:=OldMonth, Replacement:=NewMonth,


Doh! Discovered I was referencing the wrong row! Changed to 41 and all is
well :) Forgot I had recently deleted a row after macro was written.

Thanks for jumping in, though.

--
David
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 195
Default replace doesn't

Don Guillett wrote

Name the cells and refer to the name and that won't happen again


Done. Thanks.

--
David
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
Find and Replace - Replace with Blank Space Studebaker Excel Discussion (Misc queries) 4 April 3rd 23 10:55 AM
Can I replace a ' at the beginning of a text cell using Replace Hilde Excel Discussion (Misc queries) 4 September 10th 07 06:22 PM
Replace dialog should put focus on "Find What" not "Replace With" Michael Williams Excel Discussion (Misc queries) 0 May 24th 06 12:45 PM
find and replace - replace data in rows to separated by commas msdker Excel Worksheet Functions 1 April 15th 06 01:00 AM
How can I use replace(alt+H) for mutiple items needing replace Gery Excel Worksheet Functions 1 June 15th 05 05:51 PM


All times are GMT +1. The time now is 07:57 AM.

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"