Home > OS >  If condition for multiple sheets at once
If condition for multiple sheets at once

Time:07-07

I have the document, where I need to change the version from time to time.

When version 1 everything works fine because the links between the given worksheets (about 20 across a whole workbook) are connected with some particular cells in the Frontsheet.

When I switch to Version 2 I can put the date and name (Planner) in the box.

enter image description here

Now, I would like to have this box updated in the bottom right corner of every worksheet

enter image description here

I tried:

 Sub Version2()


 Range("J5").Value = Date

 Columns("J").ColumnWidth = 15
 Columns("J:M").HorizontalAlignment = xlCenter

 a = Application.Worksheets.Count

 For i = 1 To a
 Worksheets(i).Activate
 ActiveSheet.Cells(14, 47).Value = "=Frontsheet!J6"
 Next

 End Sub

 If Range("D38") = 2 Then
 Call Version2
 End If

but it didn't work. Works just the first part without the loop

Is there any chance of making it working across a whole workbook?

CodePudding user response:

Try this. For some reason the 14,47 address was coming up in the watch screen in the debugger as AU14.

Sub Version2()
    Range("J5").Value = Date
    
    Columns("J").ColumnWidth = 15
    Columns("J:M").HorizontalAlignment = xlCenter
    
    a = Application.Worksheets.Count
    
    For i = 1 To a
        Worksheets(i).Cells(47, 16).Formula = "=" & Worksheets(1).Name & "!" & Cells(6, 10).Address
    Next
End Sub
  • Related