Copy & Paste cells dependent on value

Hi,

Im creating a financial projection worksheet but haven't decided on when 
each product will launch.
I want C6 value if = 1 to copy E5:P5 and paste at E5:P5
if C6 = 2 copy  E5:P5 and paste at f5:q5
if C6 = 3 copy  E5:P5 and paste at g5:r5
ect

THis is the code I came up with:
Sub Macro1()
 Sheets("Revenue table").Select
    cval = Range("C6")
    Sheets("OpenCAM Quarterly Projections").Select
    Range("E5:P5").Select
    Selection.Clear
    Range("E5").Select
    Range(Selection, Selection.End(xlToRight)).Select
    Selection.Copy
    If cval = 1 Then
    Range("E5").Select
    ActiveSheet.Paste
    ElseIf cval = 2 Then
    Range("F5").Select
    ActiveSheet.Paste
    ElseIf cval = 3 Then
    Range("G5").Select
    ActiveSheet.Paste
    End If
End Sub

It runs fine when value =1 but anything else it has an error msg.
Error msg: Run-time error 1004
click a single cell, and then paste
or select a rectangle that's te same size and shape, then paste

Can anyone please help?
0
Utf
3/8/2010 2:27:01 AM
excel.programming 6508 articles. 2 followers. Follow

2 Replies
1017 Views

Similar Articles

[PageSpeed] 9

Try this sligthly modified code:

Sub Macro1()
Sheets("OpenCAM Quarterly Projections").Select
Range("E5:P5").Clear
Range("E5", Range("E5").End(xlToRight)).Copy
Select Case Sheets("Revenue table").Range("C6")
Case 1
    Range("E5").Paste
Case 2
    Range("F5").Paste
Case 3
    Range("G5").Paste
End Select
Application.CutCopyMode =3D False
End Sub

Regards,
Per

On 8 Mar., 03:27, Sentos <Sen...@discussions.microsoft.com> wrote:
> Hi,
>
> Im creating a financial projection worksheet but haven't decided on when
> each product will launch.
> I want C6 value if =3D 1 to copy E5:P5 and paste at E5:P5
> if C6 =3D 2 copy =A0E5:P5 and paste at f5:q5
> if C6 =3D 3 copy =A0E5:P5 and paste at g5:r5
> ect
>
> THis is the code I came up with:
> Sub Macro1()
> =A0Sheets("Revenue table").Select
> =A0 =A0 cval =3D Range("C6")
> =A0 =A0 Sheets("OpenCAM Quarterly Projections").Select
> =A0 =A0 Range("E5:P5").Select
> =A0 =A0 Selection.Clear
> =A0 =A0 Range("E5").Select
> =A0 =A0 Range(Selection, Selection.End(xlToRight)).Select
> =A0 =A0 Selection.Copy
> =A0 =A0 If cval =3D 1 Then
> =A0 =A0 Range("E5").Select
> =A0 =A0 ActiveSheet.Paste
> =A0 =A0 ElseIf cval =3D 2 Then
> =A0 =A0 Range("F5").Select
> =A0 =A0 ActiveSheet.Paste
> =A0 =A0 ElseIf cval =3D 3 Then
> =A0 =A0 Range("G5").Select
> =A0 =A0 ActiveSheet.Paste
> =A0 =A0 End If
> End Sub
>
> It runs fine when value =3D1 but anything else it has an error msg.
> Error msg: Run-time error 1004
> click a single cell, and then paste
> or select a rectangle that's te same size and shape, then paste
>
> Can anyone please help?

0
Per
3/8/2010 2:56:42 AM
Just read your post again, and realized that you want to copy a fixed
range,so this is better. Also I do not understand why you clear E5:P5,
and then try to copy this (empty) range. In this case I think using
'Cut' rather than ' Clear & Copy' is what you need:

Sub Macro1()
Sheets("OpenCAM Quarterly Projections").Select
Range("E5:P5").Cut
Select Case Sheets("Revenue table").Range("C6")
Case 1
    Range("E5").Paste
Case 2
    Range("F5").Paste
Case 3
    Range("G5").Paste
End Select
Application.CutCopyMode =3D False
End Sub

Regards,
Per

On 8 Mar., 03:56, Per Jessen <perjesse...@hotmail.com> wrote:
> Try this sligthly modified code:
>
> Sub Macro1()
> Sheets("OpenCAM Quarterly Projections").Select
> Range("E5:P5").Clear
> Range("E5", Range("E5").End(xlToRight)).Copy
> Select Case Sheets("Revenue table").Range("C6")
> Case 1
> =A0 =A0 Range("E5").Paste
> Case 2
> =A0 =A0 Range("F5").Paste
> Case 3
> =A0 =A0 Range("G5").Paste
> End Select
> Application.CutCopyMode =3D False
> End Sub
>
> Regards,
> Per
>
> On 8 Mar., 03:27, Sentos <Sen...@discussions.microsoft.com> wrote:
>
>
>
> > Hi,
>
> > Im creating a financial projection worksheet but haven't decided on whe=
n
> > each product will launch.
> > I want C6 value if =3D 1 to copy E5:P5 and paste at E5:P5
> > if C6 =3D 2 copy =A0E5:P5 and paste at f5:q5
> > if C6 =3D 3 copy =A0E5:P5 and paste at g5:r5
> > ect
>
> > THis is the code I came up with:
> > Sub Macro1()
> > =A0Sheets("Revenue table").Select
> > =A0 =A0 cval =3D Range("C6")
> > =A0 =A0 Sheets("OpenCAM Quarterly Projections").Select
> > =A0 =A0 Range("E5:P5").Select
> > =A0 =A0 Selection.Clear
> > =A0 =A0 Range("E5").Select
> > =A0 =A0 Range(Selection, Selection.End(xlToRight)).Select
> > =A0 =A0 Selection.Copy
> > =A0 =A0 If cval =3D 1 Then
> > =A0 =A0 Range("E5").Select
> > =A0 =A0 ActiveSheet.Paste
> > =A0 =A0 ElseIf cval =3D 2 Then
> > =A0 =A0 Range("F5").Select
> > =A0 =A0 ActiveSheet.Paste
> > =A0 =A0 ElseIf cval =3D 3 Then
> > =A0 =A0 Range("G5").Select
> > =A0 =A0 ActiveSheet.Paste
> > =A0 =A0 End If
> > End Sub
>
> > It runs fine when value =3D1 but anything else it has an error msg.
> > Error msg: Run-time error 1004
> > click a single cell, and then paste
> > or select a rectangle that's te same size and shape, then paste
>
> > Can anyone please help?- Skjul tekst i anf=F8rselstegn -
>
> - Vis tekst i anf=F8rselstegn -

0
Per
3/8/2010 3:06:34 AM
Reply:

Similar Artilces:

DVD Copy Pro for Mac
[b]DVD Copy Pro for Mac[/b] is a DVD copy software that can support D9 to D5 compression. With simple operation, it can save DVD in four different ways including directly burning to DVD disc, saving as DVD folder, copying into DVD media format that can be played by DVD Player directly, and converting as ISO file for easy movie management. Now this cool Mac DVD Copy also supports the latest released Snow Leopard. You can download [b][url=http://www.dvd-copy-mac.net/download/dvd-copy-pro-mac.zip]DVD Copy Pro for Mac[/url][/b] freely right now. [b]More information:[/b][quote]http://www.dvd-...

Picture behind text in Cells
Is there any way in which a picture can be sent behind the text in the worksheet cells? Or round the other way, is there any way to show the cells contents in front of a picture? Many thanks Bezza Format\sheet\background should do the trick RES That is a valid command. Unfortunately I've got numerous different images that need to be displayed behind cells. I need to use the cells so that the values displayed infront of the different pictures can be used in forumula's. Bezza That is a valid command. Unfortunately I've got numerous different images that need to be displaye...

Display Cell
How can I display text, for example 1.98 x 106 x T-0.63 (1.98 x 10 to the power 6 x T to the power -0.63)? Hi select these characters in the formular bar and goto 'Format - Cells - Font' -- Regards Frank Kabel Frankfurt, Germany "Excelhelp" <Excelhelp@discussions.microsoft.com> schrieb im Newsbeitrag news:3B96F0D2-F8DA-4901-873F-3391273E3FE1@microsoft.com... > How can I display text, for example 1.98 x 106 x T-0.63 (1.98 x 10 to the > power 6 x T to the power -0.63)? ...

Can I "unlock" just one cell in a protected worksheet?
Is there any way I can unlock just one cell in a protected worksheet without removing the protection from the entire worksheet? I am working on a fairly complex worksheet that has 10-15 data entry cells. The rest of the worksheet contains formulas and informational text. I have the formulas pretty much debugged and working. I am now down to making mostly cosmetic changes to the text and formatting. I have marked all of the data entry cells in a different color to help me keep from overwriting a formula, but it still happens occasionally. I usually catch it right away and can recover with ...

Truncating cells
Hello, I have a spreadsheet full of student names (Last, First, Middle) each in a separate column. I need to shorten the Middle Name column down to just the Middle Initial (1 character). It would be nice to do these using a function rather that edit them individually. I've tried the truncate function but could not get that to work. Any suggestions? Thanks, Matt Verdill Greetings, You need to use the LEFT function. In a new cell, type this formula: =LEFT(A1,1) Where A1 is the cell with the Middle Name and 1 is the number of characters. James Walker, Jr. "Matt Verdill...

order by case value
If I have the following: SELECT UserID as RID ,EnvironmentID as EnvID ,@authorType as RType ,'A' as Type ,'Author' as FullType ,Case When (isnull(FirstName, '') <> '' AND isnull(LastName, '') <> '') then LastName + ', ' + FirstName When (isnull(FirstName, '') <> '' AND isnull(LastName, '') = '') then FirstName When isnull(FirstName, '') = '' then LastName End as RName ,Email as EmailAddress FROM User WHERE EnvironmentID = @Environment...

Extract numeric value from single cell
Hello, I have numeric values within a text string in a single cell. There i no conformity to the length, or the make-up of the text. There is only ever 1 numeric value (that may vary in length from 1- digits long) within the text string. I have used the find function, but is getting vary messy. Is there numeric wildcard character I can use. Im using Excel 2000 Any help would be much appreciate -- Landyma ----------------------------------------------------------------------- Landyman's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=807 View this thread: htt...

Import/copy calendar in Outlook 2003
I got a new computer and installed Office 2003, and wanted to move my calendar to the new PC. I created a new data file called Personal Folders from Old PC. I wanted to copy my calendar OVER my current one in Personal Folders, but don't see a way to do so. I can copy my old calendar into the Pesonal Folders, but can't delete the new, empty Calendar. So I have Calendar, and Calendar 1 under my Personal Folders. Any way to just import/copy my reminders/appointments into my new calendar? Thanks for any advice. Ck G'Day Cathy, 1. Use the Folder List 2. Click on the OLD Cal...

Copy info from one workbook to another?
I have a problem I have a workbook with the function i want like a discribe here. The problem is i want to split the workbook but i don`t know how. Is it possible to have a main workbook with information from other workbooks at each worksheet? I have 20 workbooks with information. I would like to have a main workbook with on sheet1 every row from the 20workbooks with category1, on sheet2 every row from the 20workbooks with category2, etc, etc. The information in the 20workbooks in always only on sheet. The Colum in which the data is has no fix end. I go to fill in the rows trough a...

Secondary Copy
Hi, My customer using Great Plains modified report(Primary Copy). Now he wants new report something similar to the modified GP report with very few changes. I tried to copy the modified report and planned to use us a secondary copy. But the report has temp tables, so I am unable to make secondary copy. Can some one help me in how to make a new report something similar to the modified report, where to launch it. Whether it is possible throught VBA & Modifier? Regards Selvakumar.S A report with a temporary table can only be a primary copy. This is because only a primary copy can b...

local copy of mail
How do you store a copy of all your mail on you local computer when using Exchange? You setup an OST/Offline Folders file. Check with your mail admin if they support that configuration. "Brandon Baker" <brandon@discussions.microsoft.com> wrote in message news:epNKuJ19FHA.4004@TK2MSFTNGP14.phx.gbl... > How do you store a copy of all your mail on you local computer when using > Exchange? > ...

Calculate max value in specific range
Hi all, I've got a table with specific date values (start & end dates) like this: 3/23/00 Start 3/26/00 End etc. note: the length of days will vary from time tot time. -- I also have a table with all date values and corresponding numbers, like this: Column: A B Row: 1 3/23/00 1101.16 2 3/24/00 1106.16 3 3/25/00 1143.07 (=MAX) 4 3/26/00 1137.54 -- How can I calculate the max value from all those corresponding numbers between a Start- & End date? (1143.07 in this case) I've already tried the Vlookup and Max function but that only refers to 1 value (as...

Outlook 2000 SP3
How can I copy my mail and calendar to CD so that I can take my received and sent mail history to a new computer with Outlook installed? Thanks. >-----Original Message----- >How can I copy my mail and calendar to CD so that I can >take my received and sent mail history to a new computer >with Outlook installed? Thanks. >. > All your data saves in C:\Documents and Settings\Username\Local Settings\Application Data\Microsoft\Outlook\archive.pst and C:\Documents and Settings\Evgeni\Local Settings\Application Data\Microsoft\Outlook\outlook.pst You can either install instan...

Text to column and paste special transpose
Hi All, I have 1 table like this item_number qty ref 00010-001 3 U34,U36,U43 00013-001 2 U16,U21 12505-001 3 U32,U33,U42 12512-001 3 U5,U6,U27 and 1 want it to become like this item_number qty ref 00010-001 3 U34 00010-001 3 U36 00010-001 3 U43 00013-001 2 U16 00013-001 2 U21 12505-001 3 U32 12505-001 3 U33 12505-001 3 U42 12512-001 3 U5 12512-001 3 U6 12512-001 3 U27 Anybody can help me to program it in macro.. usually i do it manually and have to redo again do to careless. After using Text to Columns on Column C.......comma delimited.........Run the Reorganize macro. Sub ReOrganize...

Any idea why this is giving me a #Value! Error?
Function FrstLtrs(MyStr As String) As String Dim temp Dim i As Long TmpStr = Split(Trim(MyStr)) 'MsgBox "String" + TmpStr For i = 0 To UBound(TmpStr) If Not (UCase(TmpStr) = "OF") And Not (UCase(TmpStr) = "FOR") And Not (UCase(TmpStr) = "THE") And _ Not (UCase(TmpStr) = "AND") And Not (UCase(TmpStr) = "A") Then If Asc(Left(TmpStr(i), 1)) >= 65 And _ Asc(Left(TmpStr(i), 1)) <= 90 Then FrstLtrs = FrstLtrs & Left(TmpStr(i), 1) End If End If Next End Function Find the mo...

Copy picture ossice wizard
I have project 2007 standard edition, but the button is not working at all? Any suggestions Hi, The wizard is IMHO useless. Go to Roport, Copy Picture and do without the Wizard what millions have done before the Wizard existed. HTH -- Jan De Messemaeker Microsoft Project Most Valuable Professional +32 495 300 620 For availability check: http://users.online.be/prom-ade/Calendar.pdf "Enrique" <Enrique@discussions.microsoft.com> wrote in message news:72B5AA6C-67AE-468D-B6AE-FF16F52E57BD@microsoft.com... >I have project 2007 standard edition, but the bu...

Need value to show from a different table...
I have a form that has a data source of qry_login.I want to display a value from a table qry_SQLConnect called "SQLServerDB"I used the expression builder and came up with this, =qry_SQLConnect.SQLServerDB, but when I view the form I just get #Name?Can I have the form based on one source and a test box display a value from a different source?Any help would be appreciated!!!Kelvin Use the DLookup function:=DLookup("SQLServerDB", "qry_SQLConnect")-- Doug Steele, Microsoft Access MVPhttp://I.Am/DougSteele(no private e-mails, please)"Kelvin Beaton" <kelvi...

Paste Values not working in Excel 2003 (?)
Hi, Using Excel 2003 with Win xp Pro I copy a range of cels, then I choose EDIT > PASTE SPECIAL > VALUES and it does NOT paste ALL the cel contentent... It does paste all the cels, but only the first 3 lines of each cel's content. Is there any limitation in the number of characters ? Thanks ALex This is not the exact problem you describe, put perhaps it's related: XL2000: "255 Characters in Cell" Error When Copying Worksheet, at: http://support.microsoft.com/default.aspx?scid=kb;en-us;213548 -- HTH - -Frank Isaacs Dolphin Technology Corp. http://vbapro.com ...

Copy and paste versus copy and insert copied cells
What is the difference between these commands? Try them, it is pretty easy to see the difference -- Regards, Peo Sjoblom "Alana" <Alana@discussions.microsoft.com> wrote in message news:879FED29-5541-41B0-BB2C-7108D42ED593@microsoft.com... > What is the difference between these commands? ...

Blank cells in graph
I have a a line graph that displays customer behaviour in a number of categories. The data source for the graph is a table that refreshes every time a different 'customer' is selected from a macro drop-down list above the table, drawing data from another table. All the blank cells from the table are plotted as zero on the line graph, and I can't seem to change it so that the blank cells are not plotted on the line graph at all. I've tried going to Tools>Options>Chart, but the 'Plot empty cells as' options are all greyed out except for the 'Zero' opt...

subtotal copy and paste
Hi I have used the subtotal option in Excel and this is fine. I have also collasped the list so only the subtotal for each category is visible. However I want to copy and paste this list (just the subtotal) into another sheet When I do this it expands and shows all the results. Is it possible to just copy the visible bit. I have looked in paste special but no luck Cheers Hager On Jan 21, 6:38=A0am, Hager <Ha...@discussions.microsoft.com> wrote: > Hi > > I have used the subtotal option in Excel and this is fine. I have also > collasped the list so only the...

Copy above fails one way, copy below fails another way
I have a table of blood pressure readings that looks something like this: A B C D E 11 12 Averages: 134 83 74 13 R# Date Sys Dia Pul 14 4 8/17/08 138 87 72 15 3 8/15/08 130 84 76 16 2 8/12/08 137 83 70 17 1 8/11/08 129 79 76 Cell A14 contains =A15+1 Cell C12 contains =AVERAGE(C14:C17) Cell D12 contains =AVERAGE(D14:D17) Cell E12 contains =AVERAGE(E14:E17) Every time I take a new reading, I want to add a row to the top of the table, between row 13 (the header) and row 14 (the previous top row). I want to push a...

Business Portal "Copy to Excel" not working in Query pages
Hi, I am using Business Portal 4.0. When browsing through one of the queries pages in Business Portal, i clicked "Copy to Excel" icon. I got an error saying "The Office Web Components (OWC) must be installed to copy results to Excel." at the bottom. I am using Office 2007 on my machine. I came to know that Microsoft Office Web Components will no longer be shipping in Microsoft Office. I tried installing Office 2003 Add-in: Office Web Components from http://www.microsoft.com/downloads/details.aspx?familyid=7287252C-402E-4F72-97A5-E0FD290D4B76&displaylang=en a...

Copying graphs
Hi Is it possible to range value a graph ie I would like to copy the graph to another workbook, show all the information but without the links? Thanks You could copy the chart as a picture, then paste it wherever you want. Select the chart, hold Shift while clicking on the Edit menu, Choose Copy Picture, and select the On Screen and As Picture options, then go to the other workbook/sheet and Paste. - Jon ------- Jon Peltier, Microsoft Excel MVP Tutorials and Custom Solutions Peltier Technical Services, Inc. - http://PeltierTech.com _______ "Dixie" <Dixie@discussions.micr...

formula for cell
I have many cells with descriptive text, does anyone know of a formula where I can take for instance a cell with 500 characters and take only the first 30 and paste it in to a new cell. I have used a formula thanks to Gary =left(a1,len(a1)/2 which has worked for other uses I have--now I need to extract only the first 30 characters of a description and I have thousands of cells in my description column..Please Help =left(a1,30) Pete.Cornejo@gmail.com wrote: > > I have many cells with descriptive text, does anyone know of a formula > where I can take for instance a cell with 500...