1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Solved: copy a cell

Discussion in 'Business Applications' started by tpkelley, Jun 16, 2012.

Thread Status:
Not open for further replies.
Advertisement
  1. tpkelley

    tpkelley Thread Starter

    Joined:
    Oct 12, 2002
    Messages:
    67
    I am trying to put an exported file from an accounting program in to a excel table. I am having a problem with copying the posting month. The rows will be the variable. I may have one row or five hundred rows. Also, I may not have any cost for that month. Here is the macro I came up with. It is counting the dates, and that will not work because if a month does not have any cost, it will be off by one month from that point. here is a copy of the macro:
    Sub delcol()
    '
    ' delcol Macro
    ' to del col it exported excel
    '
    ' Keyboard Shortcut: Ctrl+d
    '
    Range("1:1,11:11,2:2,3:3,4:4,5:5,6:6,7:8,9:9,10:10").Select
    Range("A10").Activate
    Selection.Delete Shift:=xlUp
    Range("A1:D1").Select
    Selection.Cut Destination:=Range("B1:E1")
    Range("A:A,F:F,H:H,I:I,J:J,K:K,L:L,M:M,N:N,O:O,P:p,S:S").Select
    Range("S1").Activate
    Selection.Delete Shift:=xlToLeft
    Range("A2").Select
    Dim cl As Range
    For Each cl In Columns(2).SpecialCells(2)
    If IsDate(cl) Then
    Cells(Rows.Count, 14).End(xlUp).Offset(1).Resize(, 5) = cl.Resize(, 5).Value
    Cells(Rows.Count, 13).End(xlUp).Offset(1) = WorksheetFunction.CountIf(Range(Range("B1"), cl.Address), "/")
    End If
    Next cl
    Columns("M:R").Select
    Selection.Cut Destination:=Columns("H:M")
    Rows("2:2").Select
    Selection.Insert Shift:=xlDown
    Selection.Insert Shift:=xlDown
    Range("A1:E1").Select
    Selection.Cut Destination:=Range("I1:M1")
    Range("H3").Select
    ActiveCell.FormulaR1C1 = "Posting"
    Range("I3").Select
    ActiveCell.FormulaR1C1 = "Date"
    Range("J3").Select
    ActiveCell.FormulaR1C1 = "Amount"
    Range("K3").Select
    ActiveCell.FormulaR1C1 = "Vendor Number"
    Range("L3").Select
    ActiveCell.FormulaR1C1 = "Vendor Name"
    Range("M3").Select
    ActiveCell.FormulaR1C1 = "Invoice Number"
    Columns("A:G").Select
    Selection.ClearContents
    Range("H3").Select
    ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
    "Sheet1!R3C8:R234C13").CreatePivotTable TableDestination:="", TableName:= _
    "PivotTable1", DefaultVersion:=xlPivotTableVersion10
    ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet.Cells(3, 1)
    ActiveSheet.Cells(3, 1).Select
    With ActiveSheet.PivotTables("PivotTable1").PivotFields("Posting")
    .Orientation = xlRowField
    .Position = 1
    End With
    With ActiveSheet.PivotTables("PivotTable1").PivotFields("Date")
    .Orientation = xlRowField
    .Position = 2
    End With
    With ActiveSheet.PivotTables("PivotTable1").PivotFields("Vendor Name")
    .Orientation = xlRowField
    .Position = 3
    End With
    With ActiveSheet.PivotTables("PivotTable1").PivotFields("Invoice Number")
    .Orientation = xlRowField
    .Position = 4
    End With
    With ActiveSheet.PivotTables("PivotTable1").PivotFields("Amount")
    .Orientation = xlRowField
    .Position = 5
    End With
    ActiveSheet.PivotTables("PivotTable1").PivotSelect "", xlDataAndLabel, True
    ActiveSheet.PivotTables("PivotTable1").Format xlReport5
    Range("E3").Select
    ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
    "PivotTable1").PivotFields("Amount"), "Sum of Amount", xlSum
    Range("F3").Select
    With ActiveSheet.PivotTables("PivotTable1").PivotFields("Sum of Amount")
    .NumberFormat = "#,##0.00"
    End With
    Application.CommandBars("PivotTable").Visible = False
    ActiveWorkbook.ShowPivotTableFieldList = False
    End Sub
     

    Attached Files:

  2. Keebellah

    Keebellah Trusted Advisor

    Joined:
    Mar 27, 2008
    Messages:
    6,576
    First Name:
    Hans
    The layout is way off and I cannot make heads-or-tails of what you really want.
    As far as I can make out the actual rows of data start on Row 13 or 14.
    Will this always be the case? Are the top 12 rows information only?
    Could you create a sheet, based upon this sample showing how you want to look?
    The macro tells me your trying for a pivot table but it doesn't explain explain all unless somebody is willing to analyze it step-by-step.
    It is easier if you show that data as you get it and a result of like how you want it in the end.
    I'll be glad to look into it but I first need to understand it before even attempting to edit your code or write new code.
     
  3. tpkelley

    tpkelley Thread Starter

    Joined:
    Oct 12, 2002
    Messages:
    67
    here is a copy of the before and after look. I am having a problem coping the posting month.

    this is code part of the code that is giving me the problem:
    If IsDate(cl) Then
    Cells(Rows.Count, 14).End(xlUp).Offset(1).Resize(, 5) = cl.Resize(, 5).Value
    Cells(Rows.Count, 13).End(xlUp).Offset(1) = WorksheetFunction.CountIf(Range(Range("B1"), cl.Address), "/")
    End If
    Next cl

    I need it to copy the number if it is the number 1-12 if it is in column B, and copy down until a empty cell.
     

    Attached Files:

  4. Keebellah

    Keebellah Trusted Advisor

    Joined:
    Mar 27, 2008
    Messages:
    6,576
    First Name:
    Hans
    Okay,Ï'll take a look, probably after Portugal-Spain (soccer match) :)
     
  5. Garf13LD

    Garf13LD

    Joined:
    Apr 17, 2012
    Messages:
    455
    done up to before pivot
     

    Attached Files:

  6. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/1057323

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice