Solved

Macro needs help with Copy

Posted on 2014-07-17
19
102 Views
Last Modified: 2014-07-18
Folks,
This is the code I'm using
Sub InsertNewYearConsolidated()
    Dim ws As Worksheet, rw As Long
    Set ws = Worksheets("Consolidated")
    ws.Select
    
    'Insert 12 rows above Totals and the spacer row
    rw = ws.Range("A:A").Find("Totals").Row
    ws.Rows(((rw - 1) & ":" & (rw + 10))).Insert Shift:=xlDown
    
    'copy the format from the first 12 rows (6 to 17)
    ws.Range("A6:U17").Copy
    ws.Range("A" & (rw - 1)).Select
    Selection.PasteSpecial Paste:=xlPasteFormats
   Ws.Range(“A6:A17”).Copy
   Selection.PasteSpecial Paste:=xlPasteValues    
   Application.CutCopyMode = False

    Range("A1").Select
End Sub

Open in new window

In adding lines 14 and 15 I'm getting this:
Wrong fillNot exactly what I am needing which is this:
correct fill
0
Comment
Question by:Frank Freese
  • 10
  • 9
19 Comments
 
LVL 13

Expert Comment

by:duncanb7
Comment Utility
Could you send us your Excel workbook with that macro so that we can run it
at our side that assist to solve the issue quickly

Duncan
0
 

Author Comment

by:Frank Freese
Comment Utility
Sure no problem. It is attached; On the Cost Allocation Main worksheet you will find a command button with the macro
named InsertNew YearConsolidated. I added to the original code
    ws.Range("A6:A17").Copy
    Selection.PasteSpecial Paste:=xlPasteValues

Open in new window

The rest of the code is correct.
Project-Cost-Allocation-Revised1.xlsm
0
 
LVL 13

Expert Comment

by:duncanb7
Comment Utility
Sorry, ignore the previous writing, I could open it now and run it

Duncan
0
 
LVL 13

Expert Comment

by:duncanb7
Comment Utility
What is the result you want on Consolidated sheet after macro running. Could you put the data into sheet and send us in other file ?

Duncan
0
 
LVL 13

Expert Comment

by:duncanb7
Comment Utility
Please try this code

Duncan
Sub InsertNewYearConsolidated()
    Dim ws As Worksheet, rw As Long
    Set ws = Worksheets("Consolidated")
    ws.Select
    
    'Insert 12 rows above Totals and the spacer row
    rw = ws.Range("A:A").Find("Totals").Row
    ws.Rows(((rw - 1) & ":" & (rw + 10))).Insert Shift:=xlDown
   ' ws.Range("B" & (rw - 1) & ":" & "B" & (rw + 10)).NumberFormat = "dd/mm/yyyy"
    'copy the format from the first 12 rows (6 to 17)
  '  ws.Range("A6:U17").Copy
    ws.Range("A" & (rw - 1) & ":" & "A" & (rw + 10)).Select
    ws.Range("A6:A17").Copy
   Selection.PasteSpecial Paste:=xlPasteValues
 
   
    Application.CutCopyMode = False

    Range("A1").Select
End Sub

Open in new window

0
 
LVL 13

Expert Comment

by:duncanb7
Comment Utility
Please see the attached file, and you delete the rows below row17, and then re-run marco

Duncan
junk2.xlsm
0
 

Author Comment

by:Frank Freese
Comment Utility
Duncan,
This code maintains the row and column formatting needed.
Sub InsertNewYearConsolidated()
    Dim ws As Worksheet, rw As Long
    Set ws = Worksheets("Consolidated")
    ws.Select
    
    'Insert 12 rows above Totals and the spacer row
    rw = ws.Range("A:A").Find("Totals").Row
    ws.Rows(((rw - 1) & ":" & (rw + 10))).Insert Shift:=xlDown
    
    'copy the format from the first 12 rows (6 to 17)
    ws.Range("A6:U17").Copy
    ws.Range("A" & (rw - 1)).Select
    Selection.PasteSpecial Paste:=xlPasteFormats
   Application.CutCopyMode = False

    Range("A1").Select
End Sub

Open in new window

From that I get this
 correct fillThe above is correct.
What I am getting from junk2.xlsm looks like this:
incorrect fill
You give me the months Jan - Dec but not the formatting. When I'm adding to the worksheet I am also adding the months Jan - Dec in A18:A29. That's what's missing from the code snippet provided above --- adding Jan - Dec is my objective. I'm having some issues adding the year but I may post another question if I need to..
0
 
LVL 13

Expert Comment

by:duncanb7
Comment Utility
based on my attached example to solve the rest of your issue

have a nice day

Duncan
0
 

Author Comment

by:Frank Freese
Comment Utility
I'm not sure I understand your response. Are you saying that you have provided a solution?
thanks
Frank
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Author Comment

by:Frank Freese
Comment Utility
Actually, I was able to resolve this myself today. It truly was not as difficult of a fix that I though.
Thanks for your support
0
 
LVL 13

Accepted Solution

by:
duncanb7 earned 500 total points
Comment Utility
I have already done the code for the image at  http://filedb.experts-exchange.com/incoming/2014/07_w29/861307/correctfill.jpg

Is it right ?

Duncan
0
 

Author Comment

by:Frank Freese
Comment Utility
I've requested that this question be closed as follows:

Accepted answer: 0 points for fh_freese's comment #a40203317

for the following reason:

Duncan left me with the impression he had offered a solution, which unfortunately, was not the case. So I spent more time with the problem and saw how to do it myself.
I simply added this snippet:
    Range("A6:A17").Select
    Selection.Copy
    Range("A18:A29").Select
problem solved
0
 
LVL 13

Expert Comment

by:duncanb7
Comment Utility
I'd also spent  a lot time to read your question in detail  and made the code even that is not matched to your need finally.

Anyway, glad to see you have solved your problem

Have a nice day

Duncan
0
 

Author Comment

by:Frank Freese
Comment Utility
Duncan,
I tried everything you posted and displayed the results. Yes, you did add the months but the rest of the formatting was something I could not use. I closed this question when I discovered that all the new code that was needed was:
    Range("A6:A17").Select
    Selection.Copy
    Range("A18:A29").Select

Right before:
Range("A1").Select
this last line of code I had.
I personally don't collect points and if there was some way to give you partial I truly would
0
 

Author Comment

by:Frank Freese
Comment Utility
Duncan,
You are good man and dedicated to helping us. I'll have more posts of this problem for sure - my client is taking me to on a Star Trek adventure - To boldly go....
Again,
Accept my grateful thanks and appreciation
Frank
0
 

Author Comment

by:Frank Freese
Comment Utility
Duncan work on this and there is a value. I'm going to give him the points
0
 

Author Closing Comment

by:Frank Freese
Comment Utility
Thanks Duncan!
0
 
LVL 13

Expert Comment

by:duncanb7
Comment Utility
Thanks for your points

Have a nice day

Duncan
0
 

Author Comment

by:Frank Freese
Comment Utility
My pleasure. You have a great day also.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now