#1
|
|||
|
|||
how can I cut and paste a line in page1 to page 2 by clicking a button?
hello
I want to cut and paste a line in page 1 to page2 auto. for example in a1 it says page 2, a2 xxxx, a3 xxxxx and in a4 there is a save button. when I click save button it should see a1 page 2 or maybe page 3, then it cut and paste all line to page 2 or page 3. but after paste to page 2 or 3, the line must go to next line I mean in order. sorry for bad english :/ thx |
#2
|
||||
|
||||
If you have difficulties with English, I sympathize, esco, and I don't mind helping. But there are also some difficulties with the explanation. I have questions:
|
#3
|
|||
|
|||
Sorry for poor explanation. Yes I mean worksheet."So when you click the Save button, you want something in Excel to cut all the lines from somewhere and paste them to another worksheet "yes true.
"Lines" I mean for example I write something to A2 A3 and A4.after clicking save button in A5 , it will cut A2 A3 and A4 and paste to another worksheet. But excel must see which worksheet writes in A1. İf in A1 it says worksheet 2, excel must cut and paste to worksheet 2 |
#4
|
||||
|
||||
Ok, I think I understand. Tell me whether this is right:
Quote:
|
#5
|
|||
|
|||
yes it is right.
I mean after cut and paste worksheet 1 A2 and A3 to worksheet 2 A2 and A3, it should cut and paste my new data A2 and A3 in worksheet 1 to worksheet 2 next line B2 AND B3. this goes like this C3 C4 D3 D4 in worksheet 2... I want excel cut and paste my new datas to other worksheets line by order |
#6
|
||||
|
||||
Ok, I think we're almost there. Let's try this new description:
Quote:
|
#7
|
|||
|
|||
All true only in first one "Get the name of the target worksheet from A4" not A4 from A1
Pls can you explain step by step how to make this? |
#8
|
||||
|
||||
Right, sorry, A4 is where the button is; I forgot. Yes, let's go over it step by step; but plan on it taking a while, because if you've never done a VBA program before it'll take you a while to learn the pieces.
So let's start here: You're about to create an Excel macro, a program in the VBA language. Do you know where to type in your statements? If you don't, we need to start there. If you do, here are the first few statements: Code:
Sub Something() 'I don't care what you name it. Set wo = ThisWorkbook Set soFm = wo.Worksheets("Page1") snTo = soFm.Range("A1").Value MsgBox snTo End Sub 1) Sets a variable called "wo" to point to the current workbook; that allows you to refer to it later. 2) Sets a variable called "soFm" to point to the worksheet in wo that is named "Page1". If that's not what you named the first worksheet, change it in the program. I named that variable "soFm" because the "so" prefix means "sheet object" to me, and "Fm" means "From"—that is, the sheet that the data is going to be transferred from. 3) Looks at Page1!A1, and puts the contents of that cell into a variable named snTo ("sheet name To"), which is the name of the worksheet where you want the data to be cut and pasted to. 4) Displays that name to you in a message window. By the time you're done writing this program, you don't want it to display the name of the sheet, you just want the program to transfer the data; but this is a good place to write that message and test the program so you can see that it's working so far. But don't worry, it's not done yet. Try that, and tell me whether it's working right. If not, then we need to go back and figure out what's not going right. |
#9
|
|||
|
|||
yes thx a lot. I did it :P and then?
|
#10
|
||||
|
||||
Ok, let's see what's next...yes, picking up the two values in A2 and A3 and pasting them into the desired sheet. Still proceeding a few steps at a time, let's do this:
Code:
Sub Something() 'I don't care what you name it. Set wo = ThisWorkbook Set soFm = wo.Worksheets("Page1") snTo = soFm.Range("A1").Value 'collect the data from Page1 v2 = soFm.Range("A2").Value v3 = soFm.Range("A3").Value set soTo = wo.Worksheets(snTo) 'paste the data in the target sheet soTo.Range("A2").Value = v2 soTo.Range("A3").Value = v3 End Sub There are still several things wrong. For one thing, you want to cut the data from Page1, but this program is only copying it. And for another, in the new worksheet it's pasting the data in column A, but you need it to find the next free column to the right and paste it there (right?). But again, let's make sure this part is working right before we go on. Also, you should feel free to rename the variables in this program to suit your own preferences, and to add or modify the comments so that they make sense to you rather than to me. Write them in your own language, of course (what is your language, anyway?), but also have them tell you more than I've chosen to say. Before we go on to the next step, please a) confirm that your code is pasting the correct data into the correct worksheet (though not, yet, the correct column), and b) show me what your version of this program looks like so far. |
#11
|
|||
|
|||
well it looks like did something but page2 A2 A3 are still empty.
my language is Turkish. what does v2 v3 mean? I know this and works. Range("A1:A2").Select Selection.Cut Range("C4").Select ActiveSheet.Paste |
#12
|
||||
|
||||
Sorry for the delay, esco.
I was hoping that your language would be one of the ones I can read, but Turkish isn't among them. Oh, well. v2 and v3 are just the names of variables; in my program, I put the values that are in Page1!A2 and ...A3 into two variables, which I named v2 and v3, and then put them into A2 and A3 of the target worksheet. But you don't have to do it that way; you could do it directly, like this: Code:
Sub Something() 'I don't care what you name it. Set wo = ThisWorkbook Set soFm = wo.Worksheets("Page1") ' Get the target worksheet name and paste the data. snTo = soFm.Range("A1").Value set soTo = wo.Worksheets(snTo) soTo.Range("A2").Value = soFm.Range("A2").Value soTo.Range("A3").Value = soFm.Range("A3").Value End Sub |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Can you prevent an empty line from appearing in the first line of a page? | New Daddy | Word | 10 | 11-18-2013 07:01 AM |
Find, copy and paste into a new page | jperez84 | Word VBA | 24 | 09-20-2012 11:34 AM |
How to paste into another app without line numbers? | Moonf4 | Word | 1 | 04-18-2011 03:16 PM |
First line on page is truncated (top of line) | OwlCat1212 | Word | 0 | 02-14-2011 03:24 PM |
How to cut and paste a graphic to a different page in word.? | soooty | Drawing and Graphics | 1 | 08-12-2010 11:17 AM |