Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 122
  • Last Modified:

Macro needs help with Copy

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
Frank Freese
Asked:
Frank Freese
  • 10
  • 9
1 Solution
 
duncanb7Commented:
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
 
Frank FreeseAuthor Commented:
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
 
duncanb7Commented:
Sorry, ignore the previous writing, I could open it now and run it

Duncan
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
duncanb7Commented:
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
 
duncanb7Commented:
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
 
duncanb7Commented:
Please see the attached file, and you delete the rows below row17, and then re-run marco

Duncan
junk2.xlsm
0
 
Frank FreeseAuthor Commented:
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
 
duncanb7Commented:
based on my attached example to solve the rest of your issue

have a nice day

Duncan
0
 
Frank FreeseAuthor Commented:
I'm not sure I understand your response. Are you saying that you have provided a solution?
thanks
Frank
0
 
Frank FreeseAuthor Commented:
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
 
duncanb7Commented:
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
 
Frank FreeseAuthor Commented:
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
 
duncanb7Commented:
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
 
Frank FreeseAuthor Commented:
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
 
Frank FreeseAuthor Commented:
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
 
Frank FreeseAuthor Commented:
Duncan work on this and there is a value. I'm going to give him the points
0
 
Frank FreeseAuthor Commented:
Thanks Duncan!
0
 
duncanb7Commented:
Thanks for your points

Have a nice day

Duncan
0
 
Frank FreeseAuthor Commented:
My pleasure. You have a great day also.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 10
  • 9
Tackle projects and never again get stuck behind a technical roadblock.
Join Now