Consulting

Results 1 to 3 of 3

Thread: Solved: Creating new worksheets

  1. #1

    Unhappy Solved: Creating new worksheets

    Hi guys,
    This is my problem..I hope i give you exact details
    I have write a code which will perform the following

    It should open a workbook
    It should write the data in the default worksheets if they are empty...If they are not empty then it should create new worksheets and write the data on them.

    Would prefer if the creating new worksheets and write the data in them would be one function as i would to recall it several times!

    actually i need to write it in perl..but if i can get it to work in vba i can modify it!
    Last edited by Ashes.cfg; 09-28-2007 at 07:59 AM.

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Here is a shot at it

    [vba]

    Dim sFile As String

    sFile = Application.GetOpenFilename("Excel Files (*.xls), *.xls")
    If sFile <> False Then
    Workbooks.Open Filename:=sFile
    With ActiveWorkbook
    If .Worksheets(1).UsedRange.Cells.Count = 1 Then
    If .Worksheets(1).Range("A1").Value = "" Then
    .Worksheets(1).Range("A1").Value = Date
    .Worksheets(1).Range("A1").NumberFormat = "dd mmm yyyy"
    Else
    .Worksheets.Add after:=.Worksheets.Count
    .Worksheets(.Worksheets.Count).Range("A1").Value = Date
    .Worksheets(.Worksheets.Count).Range("A1").NumberFormat = "dd mmm yyyy"
    End If
    Else
    .Worksheets.Add after:=.Worksheets.Count
    .Worksheets(.Worksheets.Count).Range("A1").Value = Date
    .Worksheets(.Worksheets.Count).Range("A1").NumberFormat = "dd mmm yyyy"
    End If
    End With
    End If
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •