+ Reply to Thread
Results 1 to 4 of 4

Copy Data from one Workbook to another if condition is met but skip a column in the output

Hybrid View

  1. #1
    Registered User
    Join Date
    05-24-2013
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    5

    Copy Data from one Workbook to another if condition is met but skip a column in the output

    Hello, I need help sending Data from one worksheet to another if a condition is met. The input values in cells A, B, C, D, E, G, H, K, L, M, N, & O should be copied to output cells A, B, C, D, E, F, G, I, J, K, L, & M respectively only if the input value in P is greater than zero. Cell H in the output workbook should contain the formula =F#/G# (where # corresponds to the row number and the answer should be displayed to the tenths place) and displayed only if the values in F# & G# are filled. I hope that made sense, but I've attached a dummy Input Workbook and what the Output Workbook should look like for clarity.
    Attached Files Attached Files
    Last edited by Zandia; 05-28-2013 at 07:37 PM. Reason: To upload correct Output Workbook

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,652

    Re: Copy Data from one Workbook to another if condition is met but skip a column in the ou

    Sub TRL_Log()
        Dim a As Range
        Application.ScreenUpdating = False
        Sheets("Master Log").Copy
        ActiveSheet.Name = "TRL Log"
        On Error Resume Next
        For Each a In Range("A1:A" & Range("B" & Rows.Count).End(xlUp).Row).SpecialCells(xlCellTypeBlanks).Areas
            a.Value = a(1).Offset(-1).Value
        Next a
        Range("P1:P" & Range("B" & Rows.Count).End(xlUp).Row).SpecialCells(xlCellTypeBlanks).EntireRow.Delete
        On Error GoTo 0
        Range("F:F,I:J,P:P").Delete
        Range("H:H").Insert
        Range("H1").Value = "L/W"
        Range("H2:H" & Range("B" & Rows.Count).End(xlUp).Row).FormulaR1C1 = "=IF(Len(RC[-2])*LEN(RC[-1]),RC[-2]/RC[-1],"""")"
        Range("H:H").NumberFormat = "0.0"
        Columns.AutoFit
        Application.ScreenUpdating = True
    End Sub

  3. #3
    Registered User
    Join Date
    05-24-2013
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: Copy Data from one Workbook to another if condition is met but skip a column in the ou

    Thank you for your response! Although the formatting is correct when I run the macros, It seems to exactly copy the Input Workbook data into "Book 1" and re-formats the Input file to look like what I needed the Output file to look like.

    In other words, I need "Input Workbook" to stay the same before, during, and after the macros runs. The macros also needs to send and update data to a specific workbook named "Output Workbook". Is this possible? Any help is greatly appreciated!

  4. #4
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,652

    Re: Copy Data from one Workbook to another if condition is met but skip a column in the ou

    It does start by copying the Master Log worksheet from the Input file to a new workbook, but then it does all the filtering\formatting on the copy. The original is unchanged.

    This saves the modified copy as "Output Workbook"
    Sub TRL_Log()
        Dim a As Range
        Application.ScreenUpdating = False
        Sheets("Master Log").Copy
        'The copy is the activesheet
        ActiveSheet.Name = "TRL Log"
        On Error Resume Next
        For Each a In Range("A1:A" & Range("B" & Rows.Count).End(xlUp).Row).SpecialCells(xlCellTypeBlanks).Areas
            a.Value = a(1).Offset(-1).Value
        Next a
        Range("P1:P" & Range("B" & Rows.Count).End(xlUp).Row).SpecialCells(xlCellTypeBlanks).EntireRow.Delete
        On Error GoTo 0
        Range("F:F,I:J,P:P").Delete
        Range("H:H").Insert
        Range("H1").Value = "L/W"
        Range("H2:H" & Range("B" & Rows.Count).End(xlUp).Row).FormulaR1C1 = "=IF(Len(RC[-2])*LEN(RC[-1]),RC[-2]/RC[-1],"""")"
        Range("H:H").NumberFormat = "0.0"
        Columns.AutoFit
        'ChDrive = "C"              'Change save drive
        'ChDir "C:\Test\"           'Change save path
        ActiveWorkbook.SaveAs "Output Workbook"
        Application.ScreenUpdating = True
    End Sub

+ 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