1

I need some help Regarding VBA. I have a excel workbook with 2 sheets. In sheet 1, J1 cell I have a value which can vary. In sheet 2 I am running the following code to add values to cells.

Dim wb As Workbook
Dim nws, ws As Worksheet

Set wb = ActiveWorkbook
Set ws = wb.Sheets("Sheet1")
Set nws = wb.Sheets("Sheet2")

ws.Unprotect

With nws

.Cells(1, 2).Value2 = "0"

For i = 1 To cnt1

.Cells(j, 2).Value2 = "=.Cells(i, 2).Value2+1"

Next i

End With

I am failing in the part

=.Cells(i, 2).Value2+1

I know I'm writing it wrong. But that's the way I want the code to work.

Please excuse if I'm not putting the question correctly. Kindly help.

1 Answer 1

1
.Cells(j, 2).Value2 = "=.Cells(i, 2).Value2+1"

remove the double-quotes and the extra equals. That makes it a string, rather than evaluating the expression.

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

2 Comments

Just tried running it without quotes. .Cells(j, 2).Value2 = =.Cells(i, 2).Value2+1 Gives syntax error.
..and the extra equals sign.

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.