tiredofit
Well-known Member
- Joined
- Apr 11, 2013
- Messages
- 1,940
- Office Version
- 365
- 2019
- Platform
- Windows
I have values in cells A1, B1 and C1.
I want to shift cell B1 to the right, so the value in C1 is shifted to D1 and the value in B1 is shifted to C1.
Then I want to put the value of "abc" into cell B1.
This is my code:
This works as expected.
However, I thought it would be compact if I used a With Statement, so I changed it to:
What I found surprising was after running this second piece of code, cell B1 is blank and cell C1 contains the value "abc".
I expected cell B1 to contain the value "abc".
What is wrong?
Thanks
I want to shift cell B1 to the right, so the value in C1 is shifted to D1 and the value in B1 is shifted to C1.
Then I want to put the value of "abc" into cell B1.
This is my code:
Code:
Range("B1").Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("B1").Value2 = "abc"
This works as expected.
However, I thought it would be compact if I used a With Statement, so I changed it to:
Code:
With Range("B1")
.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
.Value2 = "abc"
End With
What I found surprising was after running this second piece of code, cell B1 is blank and cell C1 contains the value "abc".
I expected cell B1 to contain the value "abc".
What is wrong?
Thanks