Results 1 to 11 of 11

Code will run in editor but will not run with hotkey

Threaded View

  1. #1
    Registered User
    Join Date
    10-31-2013
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    10

    Code will run in editor but will not run with hotkey

    This is my first attempt at programming. This takes a comma delimited text file created by another program and converts into a format readable by a different program. When I run it through the editor immediate window it works just fine but when I run it with a hotkey it stops after opening the requested file. Any ideas would be appreciated. The attached file is the text file similar to the ones opened by this macro

    Thanks


    Sub PNA_TEST()
    '
    ' PNA_TEST Macro
    '
    
    '
      
    Dim fNameAndPath As Variant
    fNameAndPath = Application.GetOpenFilename
    If fNameAndPath = False Then Exit Sub
    Workbooks.Open Filename:=fNameAndPath
    
        
        
        
       
        Workbooks.OpenText Filename:=fNameAndPath _
            , Origin:=437, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
            xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, Semicolon:=False _
            , Comma:=True, Space:=False, Other:=False, FieldInfo:=Array(Array(1, 1), _
            Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), Array(7, 1), Array(8, 1), _
            Array(9, 1), Array(10, 1), Array(11, 1), Array(12, 1), Array(13, 1), Array(14, 1), Array(15 _
            , 1), Array(16, 2), Array(17, 1), Array(18, 1), Array(19, 1), Array(20, 1), Array(21, 1), _
            Array(22, 1), Array(23, 1), Array(24, 1), Array(25, 1), Array(26, 1), Array(27, 1), Array( _
            28, 1), Array(29, 1), Array(30, 1), Array(31, 1), Array(32, 1), Array(33, 1), Array(34, 1), _
            Array(35, 1), Array(36, 1), Array(37, 1), Array(38, 1), Array(39, 1), Array(40, 1), Array( _
            41, 1)), TrailingMinusNumbers:=True
          
        
        
        'Columns("b:b").Select
        'Selection.Delete Shift:=xlToLeft
        
    'Columns("H:L").Select
        'Range("H4").Activate
        'Selection.Delete Shift:=xlToLeft
    
    
    
    Columns("b:c").Select
        Range("b2").Activate
        Selection.Delete Shift:=xlToLeft
        
    Columns("g:g").Select
        Selection.Delete Shift:=xlToLeft
        
    Columns("h:h").Select
        Selection.Delete Shift:=xlToLeft
        
    Columns("i:k").Select
        Range("i3").Activate
        Selection.Delete Shift:=xlToLeft
        
    Columns("j:k").Select
        Range("j2").Activate
        Selection.Delete Shift:=xlToLeft
        
    Columns("k:m").Select
        Range("k3").Activate
        Selection.Delete Shift:=xlToLeft
        
    Columns("l:n").Select
        Range("l3").Activate
        Selection.Delete Shift:=xlToLeft
        
    Columns("m:o").Select
        Range("m3").Activate
        Selection.Delete Shift:=xlToLeft
        
    Columns("n:p").Select
        Range("n3").Activate
        Selection.Delete Shift:=xlToLeft
        
    Columns("p:p").Select
        Range("p4").Activate
        Selection.Delete Shift:=xlToLeft
        
    Columns("q:r").Select
        Range("q4").Activate
        Selection.Delete Shift:=xlToLeft
    
    'Columns("M:M").Select
        'Range("M4").Activate
       ' Selection.Cut
       ' Columns("F:F").Select
       ' Range("F4").Activate
       ' Selection.Insert Shift:=xlToRight
    
    Columns("e:e").Select
       Range("e4").Activate
       Selection.Cut
       Columns("a:a").Select
       Range("a4").Activate
       Selection.Insert Shift:=xlToRight
       
    Columns("b:b").Select
       Range("b4").Activate
       Selection.Cut
       Columns("i:i").Select
       Range("i4").Activate
       Selection.Insert Shift:=xlToRight
       
    Columns("c:c").Select
       Range("c4").Activate
       Selection.Cut
       Columns("b:b").Select
       Range("b4").Activate
       Selection.Insert Shift:=xlToRight
       
    Columns("e:e").Select
       Range("e4").Activate
       Selection.Cut
       Columns("i:i").Select
       Range("i4").Activate
       Selection.Insert Shift:=xlToRight
       
    Columns("i:i").Select
       Range("i4").Activate
       Selection.Cut
       Columns("f:f").Select
       Range("f4").Activate
       Selection.Insert Shift:=xlToRight
       
    Columns("i:i").Select
        Range("i4").Activate
        Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
    
    Columns("o:o").Select
       Range("o4").Activate
       Selection.Cut
       Columns("k:k").Select
       Range("k4").Activate
       Selection.Insert Shift:=xlToRight
    
    Dim lngLastRow As Long
    'Uses Column A to set the 'lngLastRow' variable _
    (find the last row) - change if required.
    lngLastRow = Cells(Rows.Count, "A").End(xlUp).Row
    
        Range("s1:s" & lngLastRow).Formula = "=g1 & ""_"" & r1"
        
        Range("w1:w" & lngLastRow).Formula = "`"
        
        Range("x1:x" & lngLastRow).Formula = "=w1 & f1"
        
      Columns("x:x").Select
        Selection.Copy
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        ActiveSheet.Paste
      
      
      
      
      Columns("x:x").Select
        Selection.Cut
        Columns("f:f").Select
        Selection.Insert Shift:=xlToRight
        
       Columns("g:g").Select
        Selection.Delete Shift:=xlToLeft
        
        Columns("w:w").Select
        Selection.Delete Shift:=xlToLeft
        
    Columns("S:S").Select
        Selection.Copy
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        ActiveSheet.Paste
     
    Columns("s:s").Select
        Selection.Cut
        Columns("G:G").Select
        Selection.Insert Shift:=xlToRight
        
     
    
    Columns("h:h").Select
        Selection.Delete Shift:=xlToLeft
    
    Columns("r:r").Select
        Selection.Delete Shift:=xlToLeft
        
    
        
     Columns("l:o").Select
        Selection.ClearContents
        
     Columns("n:o").Select
        Selection.Insert Shift:=xlToLef
        
        
        
    Columns("A:P").Select
        Columns("A:P").EntireColumn.AutoFit
    'REMOVES ALL 3/4_PLYWD MATERIAL FROM LIST
    
    
     Rows("1:1").Select
        Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
        lngLastRow = Cells(Rows.Count, "A").End(xlUp).Row
        
        Cells.Select
        Selection.AutoFilter
        ActiveSheet.Range("A1:S" & lngLastRow).AutoFilter Field:=5, Criteria1:= _
            "3/4_PLYWD"
        
        Selection.EntireRow.Delete
    
     
     
     'REMOVES ALL "*FLAT SLAB" FROM LIST
     Rows("1:1").Select
        Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
        lngLastRow = Cells(Rows.Count, "A").End(xlUp).Row
        
        Cells.Select
        Selection.AutoFilter
        ActiveSheet.Range("A1:S" & lngLastRow).AutoFilter Field:=8, Criteria1:= _
            "*FLAT SLAB"
        
        Selection.EntireRow.Delete
        
        
     'REMOVES ALL "Toe Kick" FROM LIST
      
      Rows("1:1").Select
        Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
        lngLastRow = Cells(Rows.Count, "A").End(xlUp).Row
        
        Cells.Select
        Selection.AutoFilter
        ActiveSheet.Range("A1:S" & lngLastRow).AutoFilter Field:=8, Criteria1:= _
            "Toe Kick"
        
        Selection.EntireRow.Delete
        
     'REMOVES ALL "MEDICINE CAB" FROM LIST
     
     
     Rows("1:1").Select
        Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
        lngLastRow = Cells(Rows.Count, "A").End(xlUp).Row
        
        Cells.Select
        Selection.AutoFilter
        ActiveSheet.Range("A1:S" & lngLastRow).AutoFilter Field:=8, Criteria1:= _
            "MEDICINE CAB"
        
        Selection.EntireRow.Delete
        
     'REMOVES ALL "CLOSET ROD" FROM LIST
      
      Rows("1:1").Select
        Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
        lngLastRow = Cells(Rows.Count, "A").End(xlUp).Row
        
        Cells.Select
        Selection.AutoFilter
        ActiveSheet.Range("A1:S" & lngLastRow).AutoFilter Field:=8, Criteria1:= _
            "CLOSET ROD"
        
        Selection.EntireRow.Delete
        
    
    End Sub
    Attached Files Attached Files
    Last edited by kirk70; 10-31-2013 at 01:21 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Cant open VBA code editor out of memory
    By Wade073 in forum Excel General
    Replies: 1
    Last Post: 03-19-2012, 05:33 AM
  2. Adding Hotkey to Macro with Code?
    By Neg0r in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-12-2011, 07:42 AM
  3. managing code in vba editor
    By fozze in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-30-2008, 09:55 AM
  4. Macro works in VBA editor but not when run with hotkey
    By cambotb in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-02-2008, 02:20 AM
  5. Closing the VBA Editor using code
    By Bony_Pony in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 03-07-2005, 04:10 PM

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