 |
|
|
 |
Junior Member
|
|
Mar 12, 2012, 01:49 PM
|
|
I need to to copy and paste to multiple sheets where the sheet names are not static.
I need to to copy and paste to multiple sheets where the sheet names are not static.
All it involves is the copy and paste of a formula to all the sheets in the workbook without having to refer to every book as the names of these change.
Code I am using currently =
ActiveWorkbook.Sheets.Select
Range("M3").Select
ActiveCell.FormulaR1C1 = _
"=IF(RC[-8]="""",RC[-1],IF(COUNTIF(R1C[-8]:RC[-8],RC[-8])>1,"""",SUMIF(R1C[-8]:R[25]C[-8],RC[-8],R1C[-1]:R[25]C[-1])))"
Range("
Range(").Select
Selection.Copy
Range("M4:M100").Select.Paste
Application.CutCopyMode = False]
But the macro will not copy the formula to the specified ranges.
Thanks!
|
|
 |
Junior Member
|
|
Mar 13, 2012, 09:24 AM
|
|
Solved with this decleration; If sheets <> "Blah"
Dim was As Worksheet
For Each was In Worksheets
If was.Name <> "Blah" Then '<-If sheet name is not "blah" then it will select all other sheets!
was.Range("M3").FormulaR1C1 = "=IF(RC[-8]="""",RC[-1],IF(COUNTIF(R1C[-8]:RC[-8],RC[-8])>1,"""",SUMIF(R1C[-8]:R[25]C[-8],RC[-8],R1C[-1]:R[25]C[-1])))"
Works a charm.
|
|
 |
Software Expert
|
|
Mar 13, 2012, 09:02 PM
|
|
Nicely done.
Tip: here in the forum use [CODE] tags around your code instead of [QUOTE] tags and it will format/preserve all your nice indentations. ;)
|
|
 |
Junior Member
|
|
Mar 13, 2012, 10:47 PM
|
|
Thanks, but don't have code tags, only quote, will contact admin.
|
|
 |
Junior Member
|
|
Mar 14, 2012, 10:10 AM
|
|
And even easier;
For Each was In ActiveWorkbook.Worksheets '<-Use this statement to
Was.Activate ' run code on all sheets.
|
|
 |
Software Expert
|
|
Mar 14, 2012, 11:35 PM
|
|
1) I would never recommend using was.Activate like that. Significant speed reduction when adding selecting and activating unnecessarily.
TIP: Shorter code does not equal better code. Many people can write a nice short "loop" that's only 3-4 lines of code long, and I can replace it with a non-loop 10-12 lines of code that is extremely fast on a 1000 rows of data.
1000 rows in a loop is 3000-4000 lines of vba activity in that loop, but my non-loop still processes all 1000 rows in 10 actions. You see the possible gain?
Anyway, I would stick with not be selecting.
2) The CODE tags can be manually entered using the same format you see/use for the QUOTE tags, just change the word "QUOTE" to "CODE" in the same manner.
Or, click on GO ADVANCED and you'll see the # icon for code tags.
|
|
Question Tools |
Search this Question |
|
|
Add your answer here.
Check out some similar questions!
Link spread sheets sheet 1 to sheet 2 , 2 to sheet 3
[ 4 Answers ]
I have attach what I have done on the site. What I need to do is link all of the data from sheet one to sheet 2. All I have found so far is how to link one cell to the other cell. In sheet 1 I have af 3 to af 699 . I need to bring all that data to sheet 2 to (d3 to d24) Sheet 2 will link into...
Copy and paste!
[ 2 Answers ]
I just recently purchased a new PC. (dell inspiron, windows vista)when I was with msn.had a different PC, I was able to copy pics, cartoons etc, and paste it into an email.I am now with verizon and am no longer able to copy pics , cartoons etc. all I get is the printed words.is there a reason for...
Copy and Paste
[ 4 Answers ]
Before I bought a computer with VISTA I was able to copy and past almost anything from anyplace to my desktop or email. With VISTA I am unable to do that. Can you tell me if that is just the way it is with VISTA or is there some setting or other suggestion that can help me copy and paste. I...
Copy and paste
[ 1 Answers ]
I hope someone can show me how to copy and paste a link onto my browser.I right click,it will show copy,select all in the box. What do I do next?:confused:
View more questions
Search
|