+ Reply to Thread
Results 1 to 4 of 4

Naming/Deleting workbooks

  1. #1
    Forum Contributor
    Join Date
    09-16-2004
    Posts
    100

    Naming/Deleting workbooks

    Ok, fairly long-winded explanation ahead, so apologies in advance!...

    I have an excel sheet with a variety of information, broken down into areas. What I need to do is pull the information from each area into it's own workbook. However, if there is no information for a certain area, then I don't want to create a workbook for it.

    Currently, I'm using the following code, which a) doesn't work, and b) if it did work, would result in a sheet for every area, meaning I'd have to check them all manually.

    Basically, the code creates a workbook, saves it so that I have a name for the new workbook, then checks to see if there's anything in the master sheet that needs to be transferred over (This is probably a back-to-front way of doing things, but I didn't know how to do it any other way).

    It is then meant to check the new workbook, and if it's got no data in it, save it as 'blank #'

    This way means I'm going to have to include the same chunk of code several times, as there's about 30 areas to check for.

    Any suggestions on how to make this work?

    'create workbook

    Workbooks.Add
    Application.WindowState = xlMinimized
    ActiveWorkbook.SaveAs Filename:="\Area 1.xls" _
    , FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
    ReadOnlyRecommended:=False, CreateBackup:=False

    'search for info to transfer
    num = 1
    For i = 1 To 200
    savenumber = 1
    If Workbooks("BS550DLM5").Worksheets("BS550DLM5").Cells(i, 6) = "1226" Then
    Workbooks("BS550DLM5").Worksheets("BS550DLM5").Range("A" & _
    i & ":F" & i).Copy Destination:= _
    Workbooks("Area 1").Sheets("Sheet1").Range("A" & num)
    num = num + 1

    End If
    Next i

    If Workbooks("Area 1").Sheets("Sheet1").Cells("A1").Value = "" Then
    ActiveWorkbook.SaveAs Filename:="\blank" & savenumber _
    , FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
    ReadOnlyRecommended:=False, CreateBackup:=False
    savenumber = savenumber + 1
    Else
    ActiveWorkbook.Save
    End If

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Try wrapping your code with Code tags, it's much easier to read that way.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Forum Contributor
    Join Date
    09-16-2004
    Posts
    100
    Ok. Sorry - didn't know about code tags.

    Please Login or Register  to view this content.

  4. #4
    Forum Contributor
    Join Date
    09-16-2004
    Posts
    100
    Sorry for bumping! Anyone got any ideas on this?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1