Hi, I have some simple code to copy a range from one worksheet to another:
I want to change the code so that instead of pasting to "AF27" the user can select the destination cell each time the macro is run.Sub copymacro2() Dim ws1 As Worksheet Set ws1 = Sheets("Front Page") ws1.Range("B4:F42").Select Selection.Copy Sheets("ROI").Select ActiveSheet.Select Range("AF27").Select Selection.PasteSpecial Paste:=xlPasteAllUsingSourceTheme, Operation:=xlNone _ , SkipBlanks:=False, Transpose:=False Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone _ , SkipBlanks:=False, Transpose:=False Columns("AF:AF").EntireColumn.AutoFit Columns("AG:AG").EntireColumn.AutoFit ActiveSheet.Select Range("AI27:AJ30").Select Application.CutCopyMode = False Selection.Delete Shift:=xlToLeft End Sub
How can this be achieved?
Thanks for your help.
Last edited by pike; 11-14-2011 at 01:32 PM. Reason: add code tags for newbie
Sub copymacro2() Dim ws1 As Worksheet Dim Slct As Variant Set ws1 = Sheets("Front Page") Set Slct = Application.InputBox(Prompt:="Please select a destination", Title:="Select Destination", Type:=8) ws1.Range("B4:F42").Copy Slct.PasteSpecial Paste:=xlPasteAllUsingSourceTheme, Operation:=xlNone _ , SkipBlanks:=False, Transpose:=False Slct.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone _ , SkipBlanks:=False, Transpose:=False Slct.Columns(1).EntireColumn.AutoFit Slct.Columns(2).EntireColumn.AutoFit Application.CutCopyMode = False Range(Slct.Columns(4).Rows(1).Address & ":" & Slct.Columns(5).Rows(4).Address).Delete Shift:=xlToLeft End Sub
Last edited by Whizbang; 11-14-2011 at 02:43 PM.
Can you post a sample of the excel workbook you are working in?
That's what i was after.
Many thanks for your help. Much appreciated!!
I have gone on to develop the code further for my needs.
Using this code:
Range(Slct.Columns(4).Rows(1).Address & ":" & Slct.Columns(5).Rows(4).Address).Delete Shift:=xlToLeft
i modified it to paste a copied cell in to cell ranging between Columns(1).Rows(1) and a given value for column (x) defined by another cell:
ws1.Range("C3").Copy
ws1.Range(Slct.Columns(1).Rows(1).Address & ":" & Slct.Columns(ws1.Range("E3").Value).Rows(1).Address).Paste
Is there an easy way to use the SUM of 3 cells for the select column value I.e.:
ws1.Range(Slct.Columns(1).Rows(1).Address & ":" & Slct.Columns(ws1.Range("E3").Value + ws1.Range("E4").Value + ws1.Range("E5").Value).Rows(1).Address).Paste
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks