"Move Values" button

G

Guest

Guest
I have tried for about 10 hours now to write a macro, whereby I can do the equivalent of a "cut special" and "paste special", so that I only end up moving values, and nothing else. Does anyone know where I can find such a macro already written? Or ideas on what I should do to write one? My inexperience with VBA is very frustrating!

Thank you
-Josh
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Hi

Afraid there is no such thing as a "Cut special values" but this will do a similar thing:

Dim strFormat As String
strFormat = Range("D20").NumberFormat
Range("D20") = Range("A1")
Range("D20").NumberFormat = strFormat


_________________
Kind Regards
Dave Hawley
OzGrid Business Applications
Microsoft Excel/VBA Training
If it's Excel, then it's us!
This message was edited by Dave Hawley on 2002-03-11 09:15
 
Upvote 0
I must not have done a good job explaining myself. What I need would be like a "move values" button. IOW:

1) Select a range by user input (say A1:C3 on sheet1)
2) Copy the range
3) Paste the range by user input (say B1:D3 on sheet2)
4) GO BACK AND CLEAR THE VALUES FROM THE RANGE IN STEP 1

All the user would do then, is 1) click a button, 2) select a range, 3) click ok, 4) select another range, 5) click ok.

The values would be gone from the "cut special" spot, and would be now located in the "paste special" spot. Obviously, this must all be done inside the same macro, or the orginal range would have to be cleared manually.

SURELY, someone has written a "move values" macro??!

Thanks
-Josh
 
Upvote 0
Try this ;-

Sub Cut_Paste()
Dim source As Range, dest As Range
r1:
On Error Resume Next
Application.DisplayAlerts = False
Set source = Application.InputBox("Enter or select a range", Type:=8)
Application.DisplayAlerts = True
On Error GoTo 0
If source Is Nothing Then
MsgBox "No range entered or selected"
End
ElseIf source.Areas.Count <> 1 Then
MsgBox "You must select one contiguous range only"
Set source = Nothing
GoTo r1
End If
r2:
On Error Resume Next
Application.DisplayAlerts = False
Set dest = Application.InputBox("Enter or select one cell", Type:=8)
Application.DisplayAlerts = True
On Error GoTo 0
If dest Is Nothing Then
MsgBox "No range entered or selected"
End
ElseIf dest.Cells.Count <> 1 Then
MsgBox "You must select one cell only"
Set dest = Nothing
GoTo r2
End If
source.Cut Destination:=dest
End Sub
 
Upvote 0
Well, that is getting closer. Let me clarify; the problem is that I want to only move the cell contents, NOT the formatting. I think you can now fully see my delimma. I don't think you can use a "cut" at all. It seems to me that what you have to do is 1) copy, 2) paste special values, 3) clear the copied range of values. The macro would have to keep track of the orginal range so that it can "clean up" as the last step.

Thank you, very sincerely, for your effort.

-Josh
 
Upvote 0
Wait a sec... Here it is! Thank you Arviragus. All I really had to do was change those last few lines of your code. Perhaps you erroneously assumed that I was smart enough to see this... Oh well! :)

Here it is with the change:

Sub Cut_Paste()
Dim source As Range, dest As Range
r1:
On Error Resume Next
Application.DisplayAlerts = False
Set source = Application.InputBox("Enter or select a range", Type:=8)
Application.DisplayAlerts = True
On Error GoTo 0
If source Is Nothing Then
MsgBox "No range entered or selected"
End
ElseIf source.Areas.Count <> 1 Then
MsgBox "You must select one contiguous range only"
Set source = Nothing
GoTo r1
End If
r2:
On Error Resume Next
Application.DisplayAlerts = False
Set dest = Application.InputBox("Enter or select one cell", Type:=8)
Application.DisplayAlerts = True
On Error GoTo 0
If dest Is Nothing Then
MsgBox "No range entered or selected"
End
ElseIf dest.Cells.Count <> 1 Then
MsgBox "You must select one cell only"
Set dest = Nothing
GoTo r2
End If
source.Copy
dest.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
source.ClearContents
End Sub

Thank all of you for your help
 
Upvote 0
On 2002-03-12 15:16, Anonymous wrote:
.....What I need would be like a "move values" button. IOW:

1) Select a range by user input (say A1:C3 on sheet1.........
Thanks
-Josh

Josh mate, what's "IOW" ?

ta
Chris
:)
 
Upvote 0
My apologies; that is short for "In Other Words". I use a lot of acronyms when corresponding with friends, so much so that I forget that they are not necessarily clear to other people.

-Josh
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,717
Members
448,985
Latest member
chocbudda

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