0
Sub LoopCertain() 'Excel VBA to loop through only include sheets (1-3)

Dim sh As Worksheet

For Each sh In ActiveWorkbook.Worksheets ' Start of the VBA loop
  Select Case sh.Name
    Case Is = "D1", "D2", "D3", "D4", "D5", "D6", "D7", "D8", "D9", "D10", "D11", "D12", "D13", "D13", "D14", "D15", "D16", "D17", "D18", "D19", "D20", "D21", "D22", "D23", "D24", "D25", "D26", "D27", "D28", "D29", "D30", "D31"
     sh.[D15].Value = "=(4-(D16+D17+D18+D19))+(SUMIF(J27:J38,"Operational",N27:N38))"
     sh.[D21].Value = "=4-(SUM(D16:D20))"
     sh.[D23].Value = "=D15/4"
  End Select
Next sh

End Sub

The error is on the line listed below and is caused by "Operational", I assume because it sees the " and tries to end there, how do I make it so it takes "operational" literally as is and continues past it?

sh.[D15].Value = "=(4-(D16+D17+D18+D19))+(SUMIF(J27:J38,"Operational",N27:N38))"
1
  • Are you really trying to set the .Value to those strings, or are you trying to set the .Formula to that? Commented Oct 4, 2016 at 8:03

1 Answer 1

1

You can either double the quotation marks or

sh.[D15].Value = "=(4-(D16+D17+D18+D19))+(SUMIF(J27:J38,""Operational"",N27:N38))"

use CHR(34).

sh.[D15].Value = "=(4-(D16+D17+D18+D19))+(SUMIF(J27:J38," + CHR(34) + "Operational" + CHR(34)",N27:N38))"
Sign up to request clarification or add additional context in comments.

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.