+ Reply to Thread
Results 1 to 2 of 2

Open Specific Sheet in Workbook

Hybrid View

  1. #1
    jhahes
    Guest

    Open Specific Sheet in Workbook

    I was looking to do the following.

    I have a workbook. 1 sheet

    Column A is for Name

    Column B is for Amount

    Column C is for Account Type


    The following is what I am trying to do.
    By running a macro, I would like like excel to see if the specific Account Type (Column C from Wrk book 1) Workbook is created (The workbook would be in the same directory if it is created). If the workbook exists, then go to a specific sheet - all sheets are named after the Name in column a or workbook 1. Then put the amount in the exact Name sheet in Cell A4.

    Any help would be appreciated.
    Thanks in advance

    Josh

  2. #2
    Forum Contributor
    Join Date
    11-09-2004
    Posts
    451
    Backup your workbook before trying this macro

    I am assuming that cell c2 is the workbook name , c2 is the sheet name , b2 is the amount.

    if file exist , It will open workbook, select a sheet name and assign the amount

    else it will add workbook, select a sheet name and assign the amount and save the workbook as the account name



    Sub Macro1()
    Dim acount_name, sheet_name, amount As Variant
    account_name = Range("c2").Value 'account name
    sheet_name = Range("a2").Value 'sheet names
    amount = Range("b2").Value 'amount
    On Error Resume Next
    Workbooks.Open Filename:=Range("c2").Value 'open the file
    If Err.Description <> "" Then ' if file doesnot exist
    Err.Clear
    Workbooks.Add 'create new workbook
    Sheets("sheet1").Name = sheet_name ' name the sheet1 as name from column a
    Range("a4").Value = amount ' assign the amount
    ActiveWorkbook.SaveAs account_name 'save as accountname
    Else ' if file exist
    Sheets(sheet_name).Select 'select the sheet name
    Range("a4").Value = amount 'assign the amount
    End If
    ActiveWorkbook.Save 'save
    ActiveWorkbook.Close 'close
    End Sub

+ 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