Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 573
Default Cut & insert columns not working

I've written a macro to look for a cell containing "othermed" in row 1.
If it finds "othermed", it test to see if the cell to the right is
blank. If that cell is not blank, it creates a range from the cell to
the last cell in row 1 with text. It then cuts those columns to the
right of the one containing "othermed" and pastes them in 5 columns to
the left of it. Well, it's supposed to.

Sub ColumnMove()
Dim rOthrMed As Range
Dim rTtl As Range
Dim rMove As Range
'Application.ScreenUpdating = False

Range("a1").Select
Selection.CurrentRegion.Select
Set rTtl = Range(Selection, Selection.End(xlToRight))
Set rOthrMed = rTtl.find("othermed", LookIn:=xlValues)

If Not rOthrMed Is Nothing Then


If rOthrMed.Offset(0, 1).Value < "" Then
Set rMove = Range(Selection, Selection.End(xlToRight))

rMove.EntireColumn.Cut
rOthrMed.Offset(0, -5).EntireColumn.Insert<--ERROR HERE

End If
End If


Application.ScreenUpdating = True

End Sub

When I run it I get runtime error 1004, saying it can't paste because
the ranges don't match. Can anyone tell me whatsamatta?
Thanks for the help.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 573
Default Cut & insert columns not working

I should have mentioned that the columns I'm pasting to aren't blank.
That's why I want to insert the moved columns and move the existing
ones over to the right.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 573
Default Cut & insert columns not working

I found it and fixed it! Sorry if I wasted anyone's time.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default Cut & insert columns not working

If you want to Insert the column the you have to
1. Select the Source Column
2. COPY the Source Column
3. Select the Column where you want the Insert of the Source Column to
happen, INSERT COPIED CELLS
4. Select the Source Column
5 Delete the Source Column
Although there is the Insert Cut Cells, it will work only if you first
Insert a blank Column at the Destination, then the Cut and Insert Cut Cells
command will work.
TTFN
JMMach

"davegb" wrote in message
oups.com...
I should have mentioned that the columns I'm pasting to aren't blank.
That's why I want to insert the moved columns and move the existing
ones over to the right.



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 573
Default Cut & insert columns not working


JMMach wrote:
If you want to Insert the column the you have to
1. Select the Source Column
2. COPY the Source Column
3. Select the Column where you want the Insert of the Source Column to
happen, INSERT COPIED CELLS
4. Select the Source Column
5 Delete the Source Column
Although there is the Insert Cut Cells, it will work only if you first
Insert a blank Column at the Destination, then the Cut and Insert Cut Cells
command will work.
TTFN
JMMach

"davegb" wrote in message
oups.com...
I should have mentioned that the columns I'm pasting to aren't blank.
That's why I want to insert the moved columns and move the existing
ones over to the right.


Thanks for your suggestions! Somehow, my last post, saying that I'd
solved the problem, didn't show here for hours! I posted it about 30
minutes after my previous post. So you had know way of knowing I'd
solved the problem.
It was a little simpler than what you proposed. The final version is:

Sub ColumnMove()
Dim rOthrMed As Range
Dim rTtl As Range
Dim rMove As Range
Dim rFirstCol As Range

Application.ScreenUpdating = False

Range("a1").Activate
Set rTtl = Range(Selection, Selection.End(xlToRight))
Set rOthrMed = rTtl.find("othermed", LookIn:=xlValues)

If Not rOthrMed Is Nothing Then
Set rFirstCol = rOthrMed.Offset(0, 1)
If rFirstCol.Value < "" Then
Set rMove = Range(rFirstCol, rFirstCol.End(xlToRight))
rMove.EntireColumn.Cut
rOthrMed.Offset(0, -5).EntireColumn.Insert

End If
End If

Application.ScreenUpdating = True

End Sub

Notice I cut and pasted and didn't have to go back and delete the
columns.
Thanks again!


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I insert columns of dates in between exsisting columns of PJS Excel Discussion (Misc queries) 1 December 22nd 08 03:22 PM
can no longer insert new columns & unhide hidden columns em2 Excel Worksheet Functions 1 July 19th 07 03:18 AM
unable to insert columns in excel, insert- columns (disabled) iam_leearner Excel Discussion (Misc queries) 1 August 13th 06 02:26 PM
Insert Name Function not working genius Excel Worksheet Functions 2 August 2nd 06 03:59 AM
Insert Row macro not working Acct Supr - DCTC Excel Discussion (Misc queries) 3 October 7th 05 01:11 AM


All times are GMT +1. The time now is 01:01 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"