View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Rob Bovey Rob Bovey is offline
external usenet poster
 
Posts: 811
Default Sheet Naming, and code trimming.

Hi Victor,

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?


Worksheets.Add.Name = "New"

Also is there a way to trim this?


Assuming your intention is to copy the formula to all of those other
cells, this should do it:

Range("E11").FormulaR1C1 = _
"=IF(R[-1]C="""","""",NOW()-INT(NOW()))"
Range("E14").Formula = Range("E11").Formula
Range("E17").Formula = Range("E11").Formula
Range("E20").Formula = Range("E11").Formula
Range("E23").Formula = Range("E11").Formula
Range("M11").Formula = Range("E11").Formula
Range("M14").Formula = Range("E11").Formula
Range("M17").Formula = Range("E11").Formula
Range("M20").Formula = Range("E11").Formula
Range("M23").Formula = Range("E11").Formula

--
Rob Bovey, MCSE, MCSD, Excel MVP
Application Professionals
http://www.appspro.com/

* Please post all replies to this newsgroup *
* I delete all unsolicited e-mail responses *


"Victor H" wrote in message
...
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.