MrExcel Message Board

Go Back   MrExcel Message Board > Question Forums > Excel Questions

Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only.

Reply
 
Thread Tools Display Modes
Old Mar 11th, 2002, 08:46 AM   #1
Guest
 
Posts: n/a
Default

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
  Reply With Quote
Old Mar 11th, 2002, 10:08 AM   #2
Guest
 
Posts: n/a
Default

Try this:

Selection.Copy
Range("A1").PasteSpecial Paste:=xlValues

HTH

GaryB
  Reply With Quote
Old Mar 11th, 2002, 10:13 AM   #3
Dave Hawley
Banned
 
Join Date: Feb 2002
Posts: 1,582
Default

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 ]
Dave Hawley is offline   Reply With Quote
Old Mar 12th, 2002, 04:16 PM   #4
Guest
 
Posts: n/a
Default

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
  Reply With Quote
Old Mar 12th, 2002, 05:25 PM   #5
Arviragus
 
Join Date: Mar 2002
Posts: 33
Default

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

Arviragus is offline   Reply With Quote
Old Mar 13th, 2002, 07:39 AM   #6
Guest
 
Posts: n/a
Default

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
  Reply With Quote
Old Mar 13th, 2002, 08:53 AM   #7
Guest
 
Posts: n/a
Default

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
  Reply With Quote
Old Mar 13th, 2002, 02:08 PM   #8
Chris Davison
MrExcel MVP
 
Join Date: Feb 2002
Location: Millbank, London, UK
Posts: 1,790
Default

Quote:
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
Chris Davison is offline   Reply With Quote
Old Mar 13th, 2002, 03:53 PM   #9
Guest
 
Posts: n/a
Default

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
  Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT -4. The time now is 03:07 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
All contents Copyright 1998-2012 by MrExcel Consulting.
diabetic desserts recipes recipes Diabetic Soups Holiday Pizza Recipes Popcorn Recipes Recipes For Microwave Pasta Recipes Casserole Recipes Chili Recipes Curry Recipes Crockpot Recipes Apples Recipes Bread Recipes Vegetarian Recipes Vegetable recipes Desserts Recipes Appetizers Ethnic Recipes Meat Dishes Barbecue Recipes Sauces Recipes Marinade Recipes Low Fat Recipes Frugal Gourmet Kitchen Classics Recipes On The Grill Cook Books Seafood Recipes Cajun Recipes Breads Low Fat Low Fat Breads Bread Machine Recipes Yeast Breads Quick Breads Fat Free Vegetarian Salad Recipes Eggplant Recipes Radish Recipes Tomato Recipes Jalapeno Recipes Potato Recipes Lettuce Recipes Cabbage Recipes Beans Ambrosia Recipes Biscotti Recipes Desserts Low Fat Cookie Recipes Cheesecake Recipes Cake Recipes Pie Recipes Muffin Recipes Custard Recipes Best Appetizers Appetizers Low Fat Salsa Recipes Dip Recipes International Recipes Afghan Recipes Alaska Recipes French Recipes German Recipes Greek Recipes Italian Recipes Spanish Recipes Thai Recipes Korean Recipes Chinese Recipes Mexican Recipes Indian Recipes Beef Recipes Pork Pork & Ham Pork Butts Pork Chop Recipes Pork Ribs Rulled Pork Poultry Recipes Stews Recipes Ground Beef Barbecue Grill Barbecue Smoker All Purpose Sauce BBQ Sauce Barbecue Sauce Carolina BBQ Sauce Pickle Recipes Marinades Smoking Low Fat Appetizers & Dips Low Fat Breakfast Low Fat Cakes Low Fat Cheesecakes Low Fat Cookies Low Fat Desserts Low Fat Fish & Seafood Low Fat Meats Low Fat Pasta Low Fat Pies Low Fat Salads Low Fat Sandwiches Low Fat Sauces & Condiments Low Fat Sides Low Fat Soups Low Fat Vegetarian Baker's Dozen Taste of Home Recipe Book Bon Appetit Cookbook Blacktie Cookbook Buster Cook Book Cookbook USA Cook Book Cook Book Sara's Cookbook Sara's Cookbook Appetizers and Dips Poultry recipes Diabetic recipes Holiday recipes Miscellaneous recipes 110 recipes 1986 Usenet cookbook 2900 recipes Cyberrealm recipes Great sysops of world Specialty recipes Ceideburg recipes Cheese recipes Chili recipes Fruits recipes Garlic recipes Great chefs of NY Londontowne recipes Raisins recipes Recipes for kids US Food Vegetarian recipes Bread recipes Drinks Meat Dishes Brisket recipes Caribou recipes Chicken recipes Filet mignons recipes Pork recipes Swordfish recipes Turkey recipes Pasta recipes Uncategorized recipes Ethnic recipes Canada recipes English recipes Ethiopia recipes Germany recipes Greece recipes Mexican recipes Philippines recipes Welsh recipes Microwave recipes Soups recipes Vegetable recipes Asparagus recipes Barley recipes Brown rice recipes Lentil recipes Mushrooms recipes Salads recipes Wild rice Desserts recipes Cakes recipes Chocolate recipes Cookies recipes Ice cream recipes