+ 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
    I was just going to PM you. I need your help. Sorry I didnt mean to cross post.

  2. #2
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Still no sign of the link ??

    Also need to add to the other forum otherwise it will be locked!!

    VBA Noob
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

  3. #3
    Registered User
    Join Date
    12-21-2007
    Posts
    20
    Sorry about the cross post. I didnt trully understand what I had done wrong until now. I can totally appriciate this rule. My cross post is at http://www.ozgrid.com/forum/showthread.php?t=86445

    They wont let me post this link there until after 24 hours and I will do just that tomorow when I return.

    Thanks VBA Noob for pointing that issue out.

  4. #4
    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,

    Here is the macro that has been added to your original workbook. The Validation drop down list contains 2 additional entries: a blank and "Add a Line".
    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
          End If
          
        Application.EnableEvents = True
    
    End Sub
    Sincerely,
    Leith Ross
    Attached Files Attached Files

  5. #5
    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

  6. #6
    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

  7. #7
    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