View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Gord Dibben[_2_] Gord Dibben[_2_] is offline
external usenet poster
 
Posts: 621
Default Paste failing after cut

You have to start at the right end and work back to find last column with data
in the activecell row.

Sub select_to_lastcolumn()
'select to last column in activerow, including blanks
Range(ActiveCell, Cells(ActiveCell.Row, Columns.Count).End(xlToLeft)).Select
End Sub

Note: assumes all selected rows are same length or activecell row is same
length as longest row.


Gord Dibben MS Excel MVP



On Sat, 11 Jun 2011 14:38:15 -0700 (PDT), stainless
wrote:

On Jun 11, 9:33*pm, "Jim Cone" wrote:
Application.CutCopyMode = False clears the clipboard, so that has to be done after the paste.

Excel will also clear the clipboard with the slightest provocation.
So you always want the copy/cut to occur as close as possible to the paste.
So as a test, comment out the line "Selection.AutoFilter Field:=PurchasedWantsColumnNumber"
that occurs immediately after the cut and see what happens.

Also...
* the line "Application.CutCopyMode = xlCut can be deleted.
* gPurchasedWantsColumn is not declared.
* add "Option Explicit" as the first line in the module.

If you still have problems, provide any error messages you receive and where.
Make sure you don't have an "On Error Resume Next" in the code someplace.
--
Jim Cone
Portland, Oregon USAhttp://www.mediafire.com/PrimitiveSoftware
(free and commercial excel programs)


The gPurchasedWantsColumn is defined elsewhere and, in this instance,
contains the letter J (I will reuse this for other worksheets once it
works, so the column letters will be defined outside this process.

However, did comment out the line "Selection.AutoFilter
Field:=PurchasedWantsColumnNumber" and the cut and paste now works. So
thanks for that. Clearly, this was clearing out the cut data.

However, I have another issue.

The rows that I am cutting are not being cut in their entirety. All
rows are selected but the xlToRight command is only selecting up to
the first blank column and there are values after this column i.e.
columns A to C are selected, D and E have no values, and thus the
populated columns from F onwards are not cut.

It appears I need to somehow alter the "Range(Selection,
Selection.End(xlToRight)).Select " line to get the last populated
column

Thanks in advance for your help.