Cut and Paste Macro

L

Legacy 436357

Guest
Hi is there a code that will cut and paste in a range if cell D is not blank and paste in cell B?

Thank you
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Code:
If not isnull(range("D" & i) then
Range("D" & i).copy Range("B" & i)
 
Upvote 0
I tried and it shows red on the first line. Does it have to be declared?

expected list or )
 
Last edited by a moderator:
Upvote 0
Suggest you give us more information. Your questions are too vague to give you a response. Provide a scenario with examples of what you want to happen. We are not mind readers here and really have no idea what you want to happen.
 
Upvote 0
Sorry please ignore my request. I will try to figure out what it is I need to do.

My sincere apologies for the trouble.
 
Upvote 0
Okay I think I know what I want to happen. I have dates in column A and numbers in column B. When a date is entered in column C and a number is entered in column D I want those to replace the date in column A and the number in column B.

Is this possible with a formula or does it have to be a macro to accomplish?
 
Upvote 0
Code:
Sub xjohnson()
Dim i as long, lr as long
lr = Range("A" & rows.count).end(xlup).row
For i = 1 to lr
Range("A" & i)= Range("C" & i)
Range("B" & i) = Range("D" & i)
Next i
End Sub

Standard Module
How to install your new code
Copy the Excel VBA code
Select the workbook in which you want to store the Excel VBA code
Press Alt+F11 to open the Visual Basic Editor
Choose Insert > Module
Edit > Paste the macro into the module that appeared
Close the VBEditor
Save your workbook (Excel 2007+ select a macro-enabled file format, like *.xlsm)


To run the Excel VBA code:
Press Alt-F8 to open the macro list
Select a macro in the list
Click the Run button
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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