VBA Loop through worksheets and update formula

Giggs1991

Board Regular
Joined
Mar 17, 2019
Messages
50
Hi All,

I have a list of worksheet names in "Sheet1" range B2:B100.

I would like to paste the formula : ActiveCell.FormulaR1C1 = "=CONCATENATE(Sheet1!R[1]C[1],""C25"")" into cell A1 of each worksheet mentioned in column B of Sheet1. However, the concatenate formula should keep updating for each worksheet.


For example,
For the first worksheet, the the vba should update the formula as : ActiveCell.FormulaR1C1 = "=CONCATENATE(Sheet1!R[1]C[2],""C25"")" in cell A1

For the 2nd worksheet, the the vba should update the formula as : ActiveCell.FormulaR1C1 = "=CONCATENATE(Sheet1!R[2]C[2],""C25"")" in cell A1

For the 3rd worksheet, the the vba should update the formula as : ActiveCell.FormulaR1C1 = "=CONCATENATE(Sheet1!R[3]C[2],""C25"")" in cellA1

Please help
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Hi Giggs1991,

I think this is what you're after:

VBA Code:
Option Explicit
Sub Macro1()

    Dim rngMyCell As Range
    Dim lngLastRow As Long
    Dim ws As Worksheet
    
    Application.ScreenUpdating = False
    
    lngLastRow = Sheets("Sheet1").Cells(Rows.Count, "B").End(xlUp).Row
    
    For Each rngMyCell In ThisWorkbook.Sheets("Sheet1").Range("B2:B" & lngLastRow)
        On Error Resume Next
            Set ws = ThisWorkbook.Sheets(CStr(rngMyCell))
            If Not ws Is Nothing Then
                ws.Range("A1").Formula = "=CONCATENATE(Sheet1!" & rngMyCell.Address & ",""C25"")"
            End If
            Set ws = Nothing
        On Error GoTo 0
    Next rngMyCell
    
    Application.ScreenUpdating = True

End Sub

Regards,

Robert
 
Upvote 0

Forum statistics

Threads
1,215,054
Messages
6,122,901
Members
449,097
Latest member
dbomb1414

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top