• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Copy of formula with changing its cell reference

Chintan Trivedi

New Member
I have put a formula in A1 as follow:


=if(A2>1,"Yes","No")


I want the same formula in B1 as =if(A2>1,"Yes","No").


I have more than 1000 of different formulas which needs to be pasted without changing cell reference as mentioned above.


How I can do it?


I have already put the formulas so I can not use "$" and also I need this formula in C1 with change in cell reference.


Please help me out.... (Particularly, I do not want to use Ctrl+H)
 
Hi Chintan,


You can try the below code that probably could work for you, it will change the cell reference to relative reference, absolute reference vice versa as per your need, then you can paste your formulae to other cells.

Sub Change_Cells_To_Absolute_Relative()

Dim RdoRange As Range, rCell As Range

Dim i As Integer

Dim Reply As String

Reply = InputBox("Change formulas to?" & Chr(13) & Chr(13) _

& "Relative row/Absolute column = 1" & Chr(13) _

& "Absolute row/Relative column = 2" & Chr(13) _

& "Absolute all = 3" & Chr(13) _

& "Relative all = 4")

If Reply = "" Then Exit Sub

On Error Resume Next

Set RdoRange = Selection.SpecialCells(Type:=xlFormulas)

Select Case Reply

Case 1

For Each rCell In RdoRange

If rCell.HasArray Then

If Len(rCell.FormulaArray) < 255 Then

rCell.FormulaArray = _

Application.ConvertFormula _

(Formula:=rCell.FormulaArray, _

FromReferenceStyle:=xlA1, _

ToReferenceStyle:=xlA1, ToAbsolute:=xlRelRowAbsColumn)

End If

Else

If Len(rCell.Formula) < 255 Then

rCell.Formula = _

Application.ConvertFormula _

(Formula:=rCell.Formula, _

FromReferenceStyle:=xlA1, _

ToReferenceStyle:=xlA1, ToAbsolute:=xlRelRowAbsColumn)

End If

End If

Next rCell

Case 2

For Each rCell In RdoRange

If rCell.HasArray Then

If Len(rCell.FormulaArray) < 255 Then

rCell.FormulaArray = _

Application.ConvertFormula _

(Formula:=rCell.FormulaArray, _

FromReferenceStyle:=xlA1, _

ToReferenceStyle:=xlA1, ToAbsolute:=xlAbsRowRelColumn)

End If

Else

If Len(rCell.Formula) < 255 Then

rCell.Formula = _

Application.ConvertFormula _

(Formula:=rCell.Formula, _

FromReferenceStyle:=xlA1, _

ToReferenceStyle:=xlA1, ToAbsolute:=xlAbsRowRelColumn)

End If

End If

Next rCell

Case 3

For Each rCell In RdoRange

If rCell.HasArray Then

If Len(rCell.FormulaArray) < 255 Then

rCell.FormulaArray = _

Application.ConvertFormula _

(Formula:=rCell.FormulaArray, _

FromReferenceStyle:=xlA1, _

ToReferenceStyle:=xlA1, ToAbsolute:=xlAbsolute)

End If

Else

If Len(rCell.Formula) < 255 Then

rCell.Formula = _

Application.ConvertFormula _

(Formula:=rCell.Formula, _

FromReferenceStyle:=xlA1, _

ToReferenceStyle:=xlA1, ToAbsolute:=xlAbsolute)

End If

End If

Next rCell

Case 4

For Each rCell In RdoRange

If rCell.HasArray Then

If Len(rCell.FormulaArray) < 255 Then

rCell.FormulaArray = _

Application.ConvertFormula _

(Formula:=rCell.FormulaArray, _

FromReferenceStyle:=xlA1, _

ToReferenceStyle:=xlA1, ToAbsolute:=xlRelative)

End If

Else

If Len(rCell.Formula) < 255 Then

rCell.Formula = _

Application.ConvertFormula _

(Formula:=rCell.Formula, _

FromReferenceStyle:=xlA1, _

ToReferenceStyle:=xlA1, ToAbsolute:=xlRelative)

End If

End If

Next rCell

Case Else

MsgBox "Invalid Number Entered!", vbCritical

End Select

Set RdoRange = Nothing

End Sub

P.S.- The code is taken from http://www.extendoffice.com/documents/excel/675-excel-change-absolute-reference-to-relative-reference.html

for more clarity on this, you can visit to above link.


Thanks & Regards,

Anupam Tiwari
 
Back
Top