+ Reply to Thread
Results 1 to 3 of 3

Setting variables

Hybrid View

clueless2 Setting variables 03-23-2013, 04:22 AM
Sean Thomas Re: Setting variables 03-23-2013, 04:44 AM
clueless2 Re: Setting variables 03-23-2013, 04:59 AM
  1. #1
    Registered User
    Join Date
    03-22-2013
    Location
    sklmrsdale
    MS-Off Ver
    Excel 2010
    Posts
    7

    Setting variables

    I have a macro that when the file opens only works the first time, I am told that I need to set variables. Can anyone explain or show me what I need to do please.


    Sub Macro1()

    Application.EnableEvents = False
    Application.DisplayAlerts = False
    Application.ScreenUpdating = False
    If Range("ap1").Value = "X" Then Exit Sub
    Sheets("Sheet1").Select
    Workbooks.Open Filename:="\\Ame-win2k\DriveE\MAL DATA\Projects\4 Database\Contract_DB_V1.1.xlsm" _
    , UpdateLinks:=0, ReadOnly:=True
    Sheets("Main").Select
    Range("c8:Q2000").Select
    Selection.Copy
    Windows("Packing_Note_V1.1_12_Mar_2013.xlsm").Activate
    Sheets("Sheet1").Select
    Range("A8").Select
    Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
    False, Transpose:=False
    Range("table").Select
    Selection.Sort Key1:=Range("a8"), Order1:=xlAscending, Header:=xlGuess, _
    OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
    Windows("Contract_DB_V1.1.xlsm").Activate
    ActiveWorkbook.Close savechanges:=False
    Windows("Packing_Note_V1.1_12_Mar_2013.xlsm").Activate
    Sheets("Site Label").Select
    Range("a20").Select
    Macro8
    End Sub
    Last edited by clueless2; 03-23-2013 at 04:46 AM. Reason: new to this not sure were I should be putting tags

  2. #2
    Valued Forum Contributor Sean Thomas's Avatar
    Join Date
    03-25-2012
    Location
    HerneBay, Kent, UK
    MS-Off Ver
    Excel 2007,2016
    Posts
    971

    Re: Setting variables

    Hi,
    the main thing you can come unstuck on is using windows("workbookname")

    try using this type to describe which workbook you are using
    Workbooks("Book1").Worksheets("Sheet1")
    however it is usually best to declare workbooks

    ie
    Dim wb1, wb2 as workbook
    Dim WB2filename as string
    WB2filename = "Contract_DB_V1.1.xlsm"
    set wb1 = thisworkbook
    set wb2 = workbooks(filename)
    
    'then use wb1 or wb2
    wb1.sheets("Sheet1").range("A8").select
    ' or
    with wb2.sheets("Site Label")
        .Range("A20").seect
    End with
    heres a link to a site giving info about workbooks etc
    http://www.techrepublic.com/blog/10t...-using-vba/967
    Regards
    Sean

    Please add to my reputation if you think i helped
    (click on the star below the post)
    Mark threads as "Solved" if you have your answer
    (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code:
    [code] Your code here [code]
    Please supply a workbook containing example Data:
    It makes its easier to answer your problem & saves time!

  3. #3
    Registered User
    Join Date
    03-22-2013
    Location
    sklmrsdale
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Setting variables

    Will try this out shortly and let you know how I get on, thanks.

+ 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