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

Howdy all,

I've got two spreadsheets, and old and new style, each with the same
sheets. I've written a (fair) bit of code to take all the data from teh
old style and dump it in the new style (just by copying over formulas
from cell to cell).

Problem is that cell references get messed up in the copying (I dont
use VBA copy or anything, it uses Cell.Formula values).

I also have a list of source/destination sheets and cells [the columns
of this sheet are like [dest sheet | dest cell | source sheet | source
cell]

I have written a macro to go through cells in each sheet to change cell
references from the source cell to the destination cell (eg in the
source a cell has the formula
'=((3761+262-40.5-386.6)/1000)-G8-G13-G14' and the destination cell
should have the formula '=((3761+262-40.5-386.6)/1000)-G7-G12-G13').

The problem is that calculations in the new style spreadsheet also get
updated. I have defined non-calculated cells by black text, and
calculated text by red text (the above example is in black). Is there a
way to get the replace to work ONLY on cells with red text?

Included below is the code for the replacements
Sub FixLinks()
Dim SearchRange As Range
Dim LastCell As String
Dim curSheet As String

LastCell = DetermineLastCell(ActiveSheet).Address(False, False)
Set SearchRange = Range("A1:" & LastCell)
curSheet = ActiveSheet.Name
For i = 3 To DetermineLastCell(ThisWorkbook.Worksheets(2)).Row
If curSheet = ThisWorkbook.Worksheets(2).Cells(i, 1).Value Then
SearchRange.Replace What:=ThisWorkbook.Worksheets(2).Cells(i,
4).Value, Replacement:=ThisWorkbook.Worksheets(2).Cells(i, 2)
End If
Next
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
Combine 2 VBA Replacements CVinje Excel Discussion (Misc queries) 2 October 16th 09 09:58 AM
Stop excel from reporting replacements Chris Excel Discussion (Misc queries) 1 January 7th 05 01:37 AM
Regular expressions for replacements in Excel? Shannon Jacobs[_2_] Excel Programming 8 December 29th 04 08:16 AM
HowTo Count number of replacements Tom Ogilvy Excel Programming 1 August 18th 04 02:38 AM
HowTo Count number of replacements Dick Kusleika[_3_] Excel Programming 0 August 17th 04 09:44 PM


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