Link to home
Start Free TrialLog in
Avatar of Upinder Singh
Upinder Singh

asked on

CUT & PASTE VALUES IN EXCEL USING MACRO -- SPECIFIC CELLS

Hello,

I need help to build a macro that will allow  to cut a value from the selected active cell in active worksheet (ie "sheet1") to another worksheet (ie. "sheet2") but paste in specific cell?    In other words,  want this to be done with button click, meaning I select the cell from the current worksheet "sheet1" and click button to paste cut value in "sheet2" but in a specified cell.  


Thanks!
Avatar of Martin Liss
Martin Liss
Flag of United States of America image

Sub DoIt()
' Moves the active cell to A1 on Sheet2
Selection.Cut Destination:=sheets("Sheet2").range("A1")
End Sub
After rereading your question I changed the code I posted.
test this

Sub cutandpaste()
ActiveCell.Cut Sheets(2).Range("A1")
End Sub
Avatar of Upinder Singh
Upinder Singh

ASKER

Thanks for your feedback.  So this code will cut the value in active cell and paste only to cell "A1."  Is it possible to define the destination cell so that first pasted value is A1, then second time the pasted value will fall in A2, and so on?
test this codes

Sub cutandpaste()
Dim actCell As String, destCell As String
Dim iRow As Integer
iRow = 1
actCell = ActiveCell.Address

Sheets(2).Activate
Cells(iRow, 1).Activate
Do Until ActiveCell.Value = ""
    iRow = iRow + 1
    ActiveCell.Offset(1, 0).Activate
Loop
Sheets(1).Activate
Range(actCell).Activate
ActiveCell.Cut Sheets(2).Range("A" & iRow)
End Sub

Open in new window

Very creative.  with this solution you the second pasted value is entered below the first value, third value below the second.   Instead of same column, can we make it so that values are entered in same row but next following cell?


Thanks!
So are you saying you want the pasted values to go in order into A1, B1, C1, etc.?
Better yet, please provide a sample workbook showing "before" and "after" sheet.
Sub cutandpaste2()
Dim actCell As String, destCell As String
Dim iCol As Integer
iCol = 1
actCell = ActiveCell.Address

Sheets(2).Activate
Cells(1, iCol).Activate
Do Until ActiveCell.Value = ""
    iCol = iCol + 1
    ActiveCell.Offset(0, 1).Activate
Loop
Sheets(1).Activate
Range(actCell).Activate
ActiveCell.Cut Sheets(2).Cells(1, iCol)
End Sub

Open in new window

hope this will help...please see attachment
before-after.xlsx
Try attached..

It would be helpful, if you provide range to cut.
Cut---Paste-Values.xlsm
You want to move Column D, E, F, G to J, K, L, M
You mentioned same rows, but whats the row number? From which row to which row?
Cells D,E,F,J from the "Before" tab to cells J,K,L,M in the "After" tab... please note that the pasted values should go to "After" tab.

So for example, a value enterd in D17 in "Before" tab should go to J17 in "After" tab (the difference between coumn J & D is 6).
You are saying D17 & J17 are fixed like for all columns E, F, G as well?
Please attached the formatted sheet. in your attachments, its a picture.
@Upinder Singh,

how many times are you going to change the conditions?
the example in the file should help exactly with what I am looking to do....

cells in row 11 in column D,e,f,g  in "Before" tab need to be cut-pasted in row 11 but in column J, K, L, M
File uploaded
TEST-FILE.xlsx
Ok please find attached...
Moving specific range...
Cut---Paste-Values.xlsm
Sub CutNPaste()
   Sheets("BEFORE").Select
    Range("D11:G11").Select
    Selection.Cut
    Sheets("AFTER").Select
    Range("J11").Select
    ActiveSheet.Paste
End Sub
SOLUTION
Avatar of Shums Faruk
Shums Faruk
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This is awesome....good stuff!  

Just one small ...last thing to ask... I want to to be able to press the button and stay on the "Before" page.  How can I do this?
I did sent your sheet, please check, there is button
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thank you everyone.....really mean this, amazing stuff here!