Viktor,
in answer to your first question, when you add a sheet it
automatically becomes the actie sheet, so you can use:
Sheets.Add
Activesheet.Name = "New"
to get round the naming problem.
As to the second part, one of the main thins the recorder
does which you can strip out to save time is SELECTing
ranges then working on the Selection. So your code could
be simplified to:
Range("E11").FormulaR1C1 = "=IF(R[-1]C="""","""",NOW()-INT
(NOW()))"
Range("E11").Copy
Activesheet.paste Range("E14")
Activesheet.paste Range("E17")
Activesheet.paste Range("E20")
ActiveSheet.Paste Range("E23")
Activesheet.paste Range("M11")
Activesheet.paste Range("M14")
Activesheet.paste Range("M17")
Activesheet.paste Range("M20")
Activesheet.paste Range("M23")
Activesheet.paste Range("E11")
Application.CutCopyMode = False
Range("C10").Select
However, as you appear to be pasting the formula at
regualr intervals, you could use a loop to further
simplify to:
Dim X As Integer
Dim Y as Integer
Range("E11").FormulaR1C1 = "=IF(R[-1]C="""","""",NOW()-INT
(NOW()))"
Range("E11").Copy
For X = 5 to 13 step 9
For Y = 11 to 23 step 3
Activesheet.paste cells(y,x)
Next y
next X
Application.cutcopymode = false
Range("C10").select
Cheers, Pete.
-----Original Message-----
I have the following code:
Sheets.Add
Sheets("Sheet1").Name = "New"
Is there a way to directly name the sheet without having
to go through VB naming it "SheetXX" first?
My code works only if this is the first sheet opened in
the workbook. But sometimes I need to insert other sheets
before I run the macro, therefore I would need an
absolute
naming routine rather than the one VB provides me.
Also is there a way to trim this?
Range("E11").Select
ActiveCell.FormulaR1C1 = "=IF(R[-1]C="""","""",NOW()-
INT(NOW()))"
Range("E11").Select
Selection.Copy
Range("E14").Select
ActiveSheet.Paste
Range("E17").Select
ActiveSheet.Paste
Range("E20").Select
ActiveSheet.Paste
Range("E23").Select
ActiveSheet.Paste
Range("M11").Select
ActiveSheet.Paste
Range("M14").Select
ActiveSheet.Paste
Range("M17").Select
ActiveSheet.Paste
Range("M20").Select
ActiveSheet.Paste
Range("M23").Select
ActiveSheet.Paste
Range("E11").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Range("C10").Select
This has been written using the recorder but I'm sure
there's a more elegant, leaner way to write it.
Thanks in advance for any help.
.