Copy/Paste macro
Hi! Can someone walk me through how to do the following in VBA?
I have a list of data that is 5 columns wide and n rows long.
I want to be able to highlight the data over 5 columns and however many rows I'd like, but not to exceed 35 rows.
Once selected, I want to be able to hit a hotkey and have a macro paste just the values of the selection into a box that is a range of
cells in the same sheet - ("C2:G35").
And then delete the original selection that I pasted.
I don't know how to say this in VBA and I cant yet navigate through the errors I'm getting.
But I think the code should look roughly like:
If selection.rows.count<=35
and selection.columns.count=5
then selection.copy
.range("C2").pastespecial paste:=xlvalues
selection.delete
end sub
Thank you for the help.
Solutions to the Problem Copy/Paste macro
Download SmartPCFixer for Free Now
Please note that C2:G35 contains only 34 rows.
Can the selection be any range of 5 columns and at most 35 rows? Or should it be within columns C:G? If it can be anywhere:
Sub MoveSelection()
Dim rngSrc As Range
Dim rngDst As Range
Set rngSrc = Selection
If rngSrc.Rows.Count <= 35 And rngSrc.Columns.Count = 5 Then
Set rngDst = Range("C2").Resize(rngSrc.Rows.Count, 5)
If Intersect(rngSrc, rngDst) Is Nothing Then
rngSrc.Copy
rngDst.PasteSpecial Paste:=xlPasteValues
rngSrc.ClearContents
Else
MsgBox "Source range overlaps destination range!", vbExclamation
End If
Else
MsgBox "Source range doesn't have correct dimensions!", vbExclamation
End If
End Sub
Make Sure that your Computer Meets the System Requirements
You need to double-check your computer's hardware configuration against the following Microsoft requirements. If your PC hardware is not up to par, then make sure you update where necessary before continuing:
Microsoft Windows Requirements :
- 1 gigahertz (GHz) or faster 32-bit (x86) or 64-bit (x64) processor
- 1 gigabyte (GB) RAM (32-bit) or 2 GB RAM (64-bit)
- 16 GB available hard disk space (32-bit) or 20 GB (64-bit)
If your computer meets the minimum requirements above, then continue on…
Recommended Method to Repair the Problem: Copy/Paste macro:
How to Fix Copy/Paste macro with SmartPCFixer?
1. You can Download Error Fixer here. Install it on your system. When you open it, it will perform a scan.
2. After the scan is finished, you can see the errors and problems need to be repaired. Click Fix All.
3. The Fixing part is finished, the speed of your computer will be much higher than before and the errors have been fixed.
Related: Time I Try To Open My Internet Explorer It Says (Not Responding),No System Maintenance Icon In Control Panel,How I Put Two Ip In Two Lan Card In Win 7,Excel 2007 Copying Cells Into Filtered Rows,Detect When User Adds New Column To Sheet,Can't Type Quotes In Some Forums,Im Looking For A Formula To SORT & Match To Get Max,Part II - Need Help With Nested IF(AND Statements,Task Manager (and Perfmon) Report ~50% CPU But Processes List Says System Idle Process 96%,Cannot Uninstall Juno Internet Software From Windows 7 Enterprise 32
Read More: [Solved] General Issues with IE8,[Anwsered] Connecting Windows 7 PC to TV with HDMI cable,How to Resolve - autoplay window opens & closes in a fractio,[Solved] unable to open Internet Explorer after renewing McA,Troubleshooting:How do I stop Internet Explorer popup asking \"Do you want to set internet explorer as your default page\" Error,USB Mouse freezing,IE8 Auto Complete not working,How to get a "Text to Columns" macro and other macro to work together?,IE not working message pos up when trying to attach a photo file to email,Help with password protected file
No comments:
Post a Comment