rename cells with a macro

L

leonidas

Hi,

I have a worksheet in Excel. In column B I have merged cells in pairs
of 3. It starts with 3to5 then 6to8 and so on.
In these cells there are formulas referring to a worksheet called
"Begroting Calc Won". The formulas are:
=ROW('Begroting Calc Won'!K11) in cells 3to5
=ROW('Begroting Calc Won'!K12) in cells 6to8
and so on.
I have a lot of these merged cells with formulas and tried to write a
macro to change the worksheet to which it refers from "Begroting Calc
Won" to "Begroting Calc Uti".
My code is below, but it won't work. The part with "i + j" is wrong I
think.
Can someone solve this problem? Thanks in advance!


Code:
--------------------
Sub EigenschappenComboBoxAanpassen()

Dim ws As Worksheet
Dim i As Long

Set ws = ActiveSheet

For i = 3 To 300 Step 3
For j = 8 To -192 Step -2
On Error Resume Next
Range("B" & i & ":B" & i + 2).UnMerge
Call LinkCombo(ws.Range("B" & i), "K" & i + j)
Range("B" & i & ":B" & i + 2).Merge
Next j
Next i

End Sub

Private Sub LinkCombo(pRange As Range, pLink As String)

Const MyFormula As String = "=ROW('Begroting Calc Uti'!"
With pRange
.Formula = MyFormula & pLink & ")"
End With

End Sub
 
T

Tom Ogilvy

did you turn on the macro recorder, then select the range and do

Edit=>replace

what: 'Begroting Calc Won'
with: 'Begroting Calc Uti'

then turn off the macro recorder and look at the recorded code. Modify it
so it is more general and suits your needs.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top