VBA Cut partial content/paste function

jweasl

New Member
Joined
Dec 31, 2013
Messages
8
Ok I've got it mostly figured out (I thought), but Excel doesn't like something about the code. I'm using Office 2010. When it tries to run the second line of this code, I get a 438 error:

Code:

Selection.Characters(83, Len(Selection) - 82).Cut</pre>
2qlzbpd.png


I'm guessing that Cut isn't an allowed method - but I'm not having any luck finding a list of operations I can use anywhere...
 

Some videos you may like

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.

JLGWhiz

Well-known Member
Joined
Feb 7, 2012
Messages
12,979
Office Version
  1. 2013
Platform
  1. Windows
Ok I've got it mostly figured out (I thought), but Excel doesn't like something about the code. I'm using Office 2010. When it tries to run the second line of this code, I get a 438 error:

Code:

Selection.Characters(83, Len(Selection) - 82).Cut
</PRE>
2qlzbpd.png


I'm guessing that Cut isn't an allowed method - but I'm not having any luck finding a list of operations I can use anywhere...

It is telling you that the Characters object does not support the Cut method. What you can do use the Left or Right functions to get your data moved to the destination cell, then use the Characters object to delete the unwanted portion of the text.
 

jweasl

New Member
Joined
Dec 31, 2013
Messages
8
I don't want to delete any text, I just want to move excess text to another cell. I'm trying to make it so the users don't have to manually move the content.
 

JLGWhiz

Well-known Member
Joined
Feb 7, 2012
Messages
12,979
Office Version
  1. 2013
Platform
  1. Windows
The idea is to use eithe Left() or Right() functions to capture the text you want to move from the source cell. Put that in the destination cell. Then delete that same text from the source cell using the Characters method to deleted partial strings.
Code:
Dim src As Range, dst As Range
Set src = Range("A1")
Set dst = Range("A2")
dst = Left(src.Value, 5)
src.Characters(1, 5).Delete

It is the same effect as cutting and pasting.
 

jweasl

New Member
Joined
Dec 31, 2013
Messages
8
Ok, looks like that's the right path. Can you point me to any instructions on how to get it to work? I'm changing values with no luck, and I found a really long article on working with Ranges that I'm reading through, no luck yet there either.

Thanks
 

Watch MrExcel Video

Forum statistics

Threads
1,122,652
Messages
5,597,373
Members
414,139
Latest member
okela0

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
Top