+ Reply to Thread
Results 1 to 10 of 10

Custom Order Template VBA or Macro

Hybrid View

  1. #1
    Registered User
    Join Date
    12-21-2007
    Posts
    20
    Leith,
    Thanks so much for your help. I think I have steped into another world of macros though. When I open the workbook the macro does what I need but I dont see it in the macro list. Is this running in the background somehow??? How do I enter this macro into my workbook? Also, I am not sure what to change so that it copy's everything except values such as the qty. I trully appriciate your time and help on this one.
    Thanks
    RAH

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259
    Hello RAH,

    The macro is attached to the worksheet to the by its Worksheet_Change event procedure. Whenever a cell's value is changed, the macro runs. I have made a change to blank the quantity when the line is copied. The change is marked in blue.
    Private Sub Worksheet_Change(ByVal Target As Range)
    
      Dim LastCol As Long
      Dim R As Long
      Dim vt As Long
      
        On Error Resume Next
          vt = Target.Validation.Type
          If Err.Number = 1004 Then
             Err.Clear
          End If
        On Error GoTo 0
        
        Application.EnableEvents = False
        
          R = Target.Row
          With ActiveSheet.UsedRange
            LastCol = .Columns.Count + .Column - 1
          End With
          
          If vt = xlValidateList And Cells(R, "A") = "Add a Line" Then
            Target.Offset(1, 0).EntireRow.Insert Shift:=xlDown
            Range(Cells(R, "B"), Cells(R + 1, LastCol)).FillDown
            Cells(R, "C").Value = ""
          End If
          
        Application.EnableEvents = True
    
    End Sub
    How to Save a Worksheet Event Macro
    1. Copy the macro using CTRL+C keys.
    2. Open your Workbook and Right Click on the Worksheet's Name Tab for the Worksheet the macro will run on.
    3. Left Click on View Code in the pop up menu.
    4. Paste the macro code using CTRL+V
    5. Save the macro in your Workbook using CTRL+S

    Sincerely,
    Leith ross

  3. #3
    Registered User
    Join Date
    12-21-2007
    Posts
    20
    Thats fantastic... I trully appriciate the help. Thanks so much!

+ 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