shift to right cell

vmjan02

Well-known Member
Joined
Aug 15, 2012
Messages
1,132
Office Version
  1. 365
  2. 2021
  3. 2019
  4. 2016
  5. 2013
I have this code below, but not sure as why it is giving an error

If ws.Range("C" & lastrow).Offset(0, 24).Value <> "" Then
ws.Range("C" & lastrow).Offset(0, 24).Select
ActiveCell.Insert (xlShiftToRight) --- (insert method of range class failed)
ws.Range("C" & lastrow).Offset(0, 24).Value = Date & Chr(10) & Me.TextBox13.Value
End If
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
It looks to me like you can simplify how you're referring to your range objects, both in terms of identifying them and also not selecting them (which is unnecessary). That may solve your issue
untested code:
Code:
with ws.cells(lastrow,27)
    If .Value <> "" Then
        .Insert (xlShiftToRight)
        .Value = Date & Chr(10) & Me.TextBox13.Value
    End If
end with

if you still get the error, there could be external influences - have you tried performing the task manually? Do you get an error something like "unable to perform action, objects will be shifted off the worksheet"?
 
Last edited:
Upvote 0
.Insert (xlshifttoright) is again giving the same error.
I think it is due to autofilter,
As my code does the autofilter and then need to shift right.
 
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,252
Members
452,623
Latest member
Techenthusiast

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top