Results 1 to 9 of 9

How to the office report form excel data that will be automatically filled up by macro.

Threaded View

  1. #6
    Valued Forum Contributor
    Join Date
    09-19-2008
    Location
    It varies ...
    MS-Off Ver
    Office365 - 64bit
    Posts
    862

    Re: How to the office report form excel data that will be automatically filled up by macro

    See attached file. To generate leave forms, select "Yes" in the column "Create Leave Form?" then click the button. Hope that's what you were after - for completeness, the code is below as well.
    Option Explicit
    Option Base 1
    
    Const conIDCol = "A"
    Const conNameCol = "B"
    Const conTypeCol = "C"
    Const conDeptCol = "D"
    Const conFromCol = "E"
    Const conToCol = "F"
    Const conDaysCol = "G"
    Const conYNCol = "H"
    
    Private Sub cmdCreateLeaveForm_Click()
    Dim lngLastRow As Long, i As Long
    Dim wksData As Worksheet, wksForm As Worksheet
    Dim rng As Range, cel As Range
    Dim strID As String, strName As String, strType As String, strDept As String, strFrom As String, strTo As String, strDays As String
    
        Set wksData = ThisWorkbook.Worksheets("LeaveData")
        Set wksForm = ThisWorkbook.Worksheets("FormTemplate")
        
        lngLastRow = wksData.Range(conYNCol & Rows.Count).End(xlUp).Row
        Set rng = wksData.Range(conYNCol & 2 & ":" & conYNCol & lngLastRow)
        For Each cel In rng
            If Left(cel.Value, 1) = "Y" Then
                i = i + 1
                strID = cel.Offset(0, -7).Text
                strName = cel.Offset(0, -6).Text
                strType = cel.Offset(0, -5).Text
                strDept = cel.Offset(0, -4).Text
                strFrom = Format(cel.Offset(0, -3).Text, "dd mmm yy")
                strTo = Format(cel.Offset(0, -2).Text, "dd mmm yy")
                strDays = cel.Offset(0, -1).Text
                
                'create instance of the leave form:
                wksForm.Copy after:=Worksheets(Worksheets.Count)
                ActiveSheet.Name = strName & " " & strFrom & "-" & strTo
                With ThisWorkbook.Worksheets(strName & " " & strFrom & "-" & strTo)
                    'populate fields in leave application form:
                    .Range("FORMCodeNo").Value = strID
                    .Range("FORMName").Value = strName
                    .Range("FORMDepartment").Value = strDept
                    .Range("FORMNature").Value = strType
                    .Range("FORMDateFrom").Value = strFrom
                    .Range("FORMDateTo").Value = strTo
                    .Range("FORMTotalDays").Value = strDays
                    .Range("FORMApplicationDate").Value = Format(Date, "dd mmm yy")
                    'populate fields in leave pass:
                    .Range("FORM_LP_CodeNo").Value = strID
                    .Range("FORM_LP_Name").Value = strName
                    .Range("FORM_LP_Department").Value = strDept
                    .Range("FORM_LP_ApplicationDate").Value = .Range("FORMApplicationDate").Value
                    .Range("FORM_LP_TotalDays").Value = .Range("FORMTotalDays").Value
                    .Range("FORM_LP_DateFrom").Value = .Range("FORMDateFrom").Value
                    .Range("FORM_LP_DateTo").Value = .Range("FORMDateTo").Value
                End With
            End If
        Next cel
    
        MsgBox ("Number of forms created = " & i)
        
    End Sub
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Office 2010: Transfer Form Content Control Data into Excel Database - Macro Help
    By Maredon2016 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-25-2016, 03:45 PM
  2. [SOLVED] Excel form writing filled data to another Excel file or sheet
    By G.Bregvadze in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 03-08-2014, 03:34 AM
  3. Excel macro to open an office form
    By garfman in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-18-2013, 04:30 AM
  4. [SOLVED] How do I automatically transfer data from one Excel report to another?
    By s3a in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-08-2012, 01:38 AM
  5. Replies: 2
    Last Post: 07-29-2011, 01:52 PM
  6. Automatically filled in form
    By Xathrax in forum Excel General
    Replies: 4
    Last Post: 11-17-2010, 06:53 AM
  7. macro for a form properly filled
    By corchox in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-19-2010, 10:53 PM

Tags for this Thread

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