1

I am having 4 Sheets, say...,

 STP1
 STP2
 STP3
 STP4
 STP5

I want to update all D3 cells of all the 5 sheets at same time.

I am trying in this way..,

  Worksheets(Array("STP1", "STP2", "STP3", "STP4", "STP5")).Select
  Worksheets(Array("STP1", "STP2", "STP3", "STP4",   "STP5")).Range("D3").Select
  If Worksheets(Array("STP1", "STP2", "STP3", "STP4", "STP5").Range("D3").Offset(0, 0) = "" Then
  Worksheets(Array("STP1", "STP2", "STP3", "STP4", "STP5")).Range("D3").Select.End(xlDown).Select
  End If
  ActiveCell.Offset(0, 0).Select
  ActiveCell.Value = Eng

But this is not working out... Can anyone please help me here...

3
  • Looping through all sheets is not good ? Commented Sep 14, 2016 at 11:52
  • You mean it is good?? But here I need to write code 5 times.. so tring these way Commented Sep 14, 2016 at 11:56
  • see code in my answer below (don't think it's too long) Commented Sep 14, 2016 at 12:17

2 Answers 2

1

Is this code too long (looping through all Sheets), using a Select Case where you can add as many sheets as you like.

(It is better to avoid selecting cells)

Option Explicit

Sub SelectSheets()

Dim Sht             As Worksheet

For Each Sht In ThisWorkbook.Sheets
    Select Case Sht.Name
        Case "STP1", "STP2", "STP3", "STP4", "STP5"

            If Sht.Range("D3") = "" Then
                Sht.Range("D" & Sht.Cells(Sht.Rows.Count, "D").End(xlUp).Row).Value = Eng
            Else
                Sht.Range("D3").Value = Eng
            End If

    End Select

Next Sht

End Sub
Sign up to request clarification or add additional context in comments.

1 Comment

@SwethaReddy you're welcome, thanks for accepting my answer
1

Consider:

Sub Macro1()
    Sheets(Array("STP1", "STP2", "STP3", "STP4", "STP5")).Select
    Sheets("STP1").Activate
    Range("D3").Select
    ActiveCell.Value = "whatever"
End Sub

(but I would use a loop and no Selects)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.