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

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.

Trebor76

Well-known Member
Joined
Jul 23, 2007
Messages
5,072
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
 

Forum statistics

Threads
1,181,439
Messages
5,929,924
Members
436,705
Latest member
Priti19

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
Top