+ Reply to Thread
Results 1 to 3 of 3

Macro to create a file from base file if data is availabe in defined columns

Hybrid View

  1. #1
    Registered User
    Join Date
    09-10-2014
    Location
    India
    MS-Off Ver
    10
    Posts
    44

    Macro to create a file from base file if data is availabe in defined columns

    Hi All,

    Good Evening.

    I require your help for creating Macro.

    I want to prepare a another file based on the base file if data is available under headers S A/C, A A/C, G A/C and W A/C.

    Output File
    In Output file the headers will be fixed... we need to populate the data from Base file under the correct heading if data is available in defined columns of Base file.
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor natefarm's Avatar
    Join Date
    04-22-2010
    Location
    Wichita, Kansas
    MS-Off Ver
    2016
    Posts
    1,020

    Re: Macro to create a file from base file if data is availabe in defined columns

    The following should get you started. It assumes an input sheet named "Input" and an output sheet named "Output", all in the same workbook. Make adjustments as needed. The output sheet needs to already have headings and column formatting in place. I wasn't sure what to put in the output column A, so I just have it incrementing a sequential number.

    Option Explicit
    
    Sub CopyData()
    Dim InRow As Long, OutRow As Long, OutCol As Long
    
        Sheets("Input").Select
        InRow = 4 ' 1st input data row
        With Sheets("Output")
            OutRow = .Range("D" & .Rows.Count).End(xlUp).Row ' Last current output row
            Do Until Cells(InRow, 1).Value = ""
                If Cells(InRow, 11) & Cells(InRow, 12) & Cells(InRow, 13) & Cells(InRow, 14) <> "----" Then
                    If Cells(InRow, 3).Value <> .Cells(OutRow, 2).Value Then ' New Code Details
                        OutRow = OutRow + 1 ' Create new output row
                        If .Cells(OutRow - 1, 1).Value = "" Then
                            .Cells(OutRow, 1).Value = 1
                        Else
                            .Cells(OutRow, 1).Value = .Cells(OutRow - 1, 1).Value + 1
                        End If
                        .Cells(OutRow, 2).Value = Cells(InRow, 3).Value
                        .Cells(OutRow, 3).Value = Cells(InRow, 1).Value
                        .Cells(OutRow, 4).Value = Cells(InRow, 13).Value
                        .Cells(OutRow, 5).Value = Cells(InRow, 12).Value
                        .Cells(OutRow, 6).Value = Cells(InRow, 14).Value
                        .Cells(OutRow, 7).Value = Cells(InRow, 11).Value
                        .Cells(OutRow, 17).Value = Cells(InRow, 5).Value
                        .Cells(OutRow, 18).Value = Cells(InRow, 6).Value
                        .Cells(OutRow, 19).Value = Cells(InRow, 7).Value
                        .Cells(OutRow, 20).Value = Cells(InRow, 8).Value
                        .Cells(OutRow, 21).Value = Cells(InRow, 2).Value
                        .Cells(OutRow, 22).Value = Cells(InRow, 4).Value
                    End If
                    Select Case Cells(InRow, 9).Value ' FB value
                        Case "FBR1": OutCol = 8
                        Case "FBR2": OutCol = 9
                        Case "FBR3": OutCol = 10
                        Case "FBR4": OutCol = 11
                        Case "FBR5": OutCol = 12
                        Case "FBR6": OutCol = 13
                        Case "FBR7": OutCol = 14
                        Case "M1": OutCol = 15
                        Case "E1": OutCol = 16
                        Case Else: OutCol = 0
                    End Select
                    If OutCol > 0 Then
                        .Cells(OutRow, OutCol).Value = Cells(InRow, 10).Value
                    End If
                End If
                InRow = InRow + 1
            Loop
            .Select
        End With
    End Sub
    Have fun!
    Acts 4:12
    Salvation is found in no one else, for there is no other name under heaven given to mankind by which we must be saved.

  3. #3
    Registered User
    Join Date
    09-10-2014
    Location
    India
    MS-Off Ver
    10
    Posts
    44

    Re: Macro to create a file from base file if data is availabe in defined columns

    Thank you So much.

    Its working absolutly fine. I have made some changes are per me requirement.

    Again thank you so much!!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 0
    Last Post: 04-12-2013, 07:38 AM
  2. Importing a data from a text file - user-defined file
    By DaveSev in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-01-2013, 07:02 PM
  3. Replies: 3
    Last Post: 05-03-2012, 10:56 AM
  4. Replies: 3
    Last Post: 09-30-2011, 04:35 AM
  5. Macro to copy data from csv file base on cells in existing workbook
    By wallstudio in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-30-2011, 03:29 AM

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