0

首先我不得不说我绝对没有编程的粘合剂。我什至不明白如何在这里做一个文本看起来像一个 Excel 列表。对此感到抱歉。我的问题是我必须将我们公司每个成员的电话单插入 Access-Database,并将 excle 文件也分发给每个成员。我每周都会收到一个名为 vodafone AUG_12(Vodafone 实际月份)的 Excel 工作表,其中包含超过 50000 行和几列。第一列包含几个电话号码,最后一列 (I) 包含从第一列中的号码每次拨打的费用。例如:

PhoneNu 日期时间整数。代码 城市 代码 目的地 描述 持续时间 成本

123456789 20120829 08:15:00 0049 431 12456 基尔 00:02:15 02.95
123456789 20120829 08:17:00 0049 431 12456 基尔 00:19.95 17.45
234567890 20120829 09:15:22 0031 21 5632145 里斯本 00:00:28 0.10
234567890 20120829 17:25:00 0031 21 5632145 里斯本 00:00:59 0.28
345678901 20120829 00:13:31 00351 91 5896 服务 00:03:45 2.58
345678901 20120829 06:45:13 00351 91 5896 服务 01:25:13 12.85

等等

有没有办法复制具有数字名称的新工作簿中每个数字的行,并将成本总和保存在与原始工作簿相同的文件夹中。

4

2 回答 2

1

谁对它感兴趣,您可以在下面查看我的解决方案。我的数据文件运行大约 20 分钟。得出这个结果需要时间。通过重新复制复制的宏并记录/调整它们。

Sub delete_0()
    'change directory
Workbooks.Open Filename:= _
    "G:\01_Phone_Bills\extbills\v_201212\Vodafone_Dec_12.csv" 

   'delete all rows which contains 0 in column 15 in the original invoice
   Dim i As Long
Application.ScreenUpdating = False
For i = Cells(Rows.Count, 15).End(xlUp).Row To 1 Step -1
  If Cells(i, 15) = "0" Then Rows(i).Delete
Next i
Application.ScreenUpdating = True
'startthe next macros
 Application.Run "'make it readable.xlsm'!delete_member_PhoneNumbers"
Application.Run "'make it readable.xlsm'!delete_Tx_Easy_Roaming"
Application.Run "'make it readable.xlsm'!Make_it_readable"
Application.Run "'make it readable.xlsm'!renamesheet"
Application.Run "'make it readable.xlsm'!delete_non_user_phone_numbers"
 ChDir "G:\01_Phone_Bills\extbills\v_201212"
ActiveWorkbook.SaveAs Filename:= _
    "G:\01_Phone_Bills\extbills\v_201212\Vodafone_Dec_12.xlsm", FileFormat:= _
    xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
Application.Run "'make it readable.xlsm'!Autosum_insert"
Application.Run "'make it readable.xlsm'!copy_amount"
Application.Run "'make it readable.xlsm'!delete_Bill_summery_0"
Application.Run "'make it readable.xlsm'!MakeMultipleXLSfromWB"
End Sub



Sub delete_member_PhoneNumbers()

 'delete all rows which contains phone number ... in column 10
 'in the original invoice, user have not to pay for that calls 

Dim a As Long
Application.ScreenUpdating = False
For a = Cells(Rows.Count, 10).End(xlUp).Row To 1 Step -1
  If Cells(a, 10) = "123456789" Then Rows(a).Delete
 Next a
 Application.ScreenUpdating = True


 End Sub

 Sub delete_Tx_Easy_Roaming()

'delete all rows which contains Tx Easy Roaming in column 11
'in the original invoice, user have not to pay for that fee     

Dim i As Long
Application.ScreenUpdating = False
For i = Cells(Rows.Count, 11).End(xlUp).Row To 1 Step -1
  If Cells(i, 11) = "Tx Easy Roaming" Then Rows(i).Delete
Next i
Application.ScreenUpdating = True
End Sub



 Sub Make_it_readable()
 '
 ' Convert the original invoice into a readable excel format

 ' Replace all file names

 '

 Rows("1:3").Select
 Selection.Delete Shift:=xlUp
 Cells.Select
 Cells.EntireColumn.AutoFit
 Columns("A:A").Select
 Selection.Delete Shift:=xlToLeft
 Columns("B:D").Select
 Selection.Delete Shift:=xlToLeft
 Columns("I:J").Select
 Selection.Delete Shift:=xlToLeft
 Columns("I:I").Select
 Selection.NumberFormat = "#,##0.00"
 Columns("J:L").Select
 Selection.Delete Shift:=xlToLeft
 Range("A1").Select
 ActiveCell.FormulaR1C1 = "PhoneNu"
 Range("B1").Select
 ActiveCell.FormulaR1C1 = "Date"
 Range("C1").Select
 ActiveCell.FormulaR1C1 = "Time"
 Range("D1").Select
 ActiveCell.FormulaR1C1 = "Country Code"
 Range("E1").Select
 ActiveCell.FormulaR1C1 = "City Code"
 Range("F1").Select
 ActiveCell.FormulaR1C1 = "Destination"
 Columns("F:F").Select
 Selection.NumberFormat = "0"
 Range("G1").Select
 ActiveCell.FormulaR1C1 = "Description"
 Range("H1").Select
 ActiveCell.FormulaR1C1 = "Duration"
 Range("I1").Select
 ActiveCell.FormulaR1C1 = "Cost"
 Range("J1").Select
 ActiveCell.FormulaR1C1 = "Total amount"
 Cells.Select
 Cells.EntireColumn.AutoFit
 Cells.Select
 ActiveWorkbook.Worksheets("Vodafone_Dec_12").Sort.SortFields.Clear 'replace "Voda..."
 ActiveWorkbook.Worksheets("Vodafone_Dec_12").Sort.SortFields.Add Key:=Range( _
    "A2:A50000"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
    xlSortNormal
 With ActiveWorkbook.Worksheets("Vodafone_Dec_12").Sort 'replace "Voda..."
    .SetRange Range("A1:R50000")
    .Header = xlYes
    .MatchCase = False
    .Orientation = xlTopToBottom
    .SortMethod = xlPinYin
    .Apply
 End With
 Columns("A:A").Select
 Selection.NumberFormat = "## #######"
 ActiveSheet.Name = "Bill Summery"

  'create the number of sheets which you need
    Dim lnumber As String
    Dim i As Long
     Anf:
    lnumber = InputBox("How often should the macro run ?", , 3)

     'check the input for a figure
   If IsNumeric(lAnzahl) Then
    For i = 1 To CLng(lnumber)
        Range("A:A:J:J").Select
        Selection.Copy
        Sheets.Add After:=Sheets(Sheets.Count)
        ActiveSheet.Paste

     Next i
  Else
     MsgBox "Please enter a figure !", vbInformation
    GoTo Anf
End If


End Sub

Sub renamesheet()
'
' renames each sheet
'

 '

Sheets("Sheet1").Name = "Tel 123456789"
Sheets("Sheet2").Name = "Tel 234567890"
Sheets("Sheet3").Name = "Tel 345678901"


Public Sub delete_non_user_phone_numbers()

'delte all pfone numbers without that from the user

'Sheet activation
 Sheets("Tel 123456789").Select
 'find last row
 lz = Cells(Rows.Count, 1).End(xlUp).Rows.Row
 'check all rows
 For t = lz To 2 Step -1 'count back to row 2
 'check if ther is "..."in the first column
 If Not Cells(t, 1).Value = "123456789" Then
    Rows(t).Delete Shift:=xlUp
  End If
 Next t
 'Sheet activation
 Sheets("Tel 234567890").Select
      lz = Cells(Rows.Count, 1).End(xlUp).Rows.Row
 For t = lz To 2 Step -1 
 If Not Cells(t, 1).Value = "234567890" Then
    Rows(t).Delete Shift:=xlUp
End If
 Next t
'Sheet activation
 Sheets("Tel 345678901").Select
 lz = Cells(Rows.Count, 1).End(xlUp).Rows.Row
 For t = lz To 2 Step -1 
 If Not Cells(t, 1).Value = "345678901" Then
    Rows(t).Delete Shift:=xlUp
 End If
 Next t


  Sub Autosum_insert()

'do the autosum in each sheet column I and fill it in J2

ActiveWindow.ScrollWorkbookTabs Position:=xlFirst
Sheets("Bill Summery").Select
Columns("A:J").Select
Selection.Delete Shift:=xlToLeft
ActiveWindow.ScrollWorkbookTabs Position:=xlLast
Sheets(Array("Bill Summery", "Tel 123456789", "Tel 234567890", "Tel 345678901")).Select
Sheets("Bill Summery").Activate

Dim intI As Integer
For intI = 2 To ThisWorkbook.Worksheets.Count
Range("J2").Select
ActiveCell.FormulaR1C1 = "=SUM(RC[-1]:R[1111]C[-1])"

Next intI
End Sub



 Sub copy_amount()
 '
 ' copy_amount Macro
 '
 'copy A1 and J2 from every sheet in Bill Summery
 '
 Sheets("Tel 123456789").Select
 Range("J2,A2").Select
 Selection.Copy
 Sheets("Bill Summery").Select
 Range("A1:B1").Select
 ActiveSheet.Paste

 Sheets("Tel 234567890").Select
 Range("J2,A2").Select
 Selection.Copy
 Sheets("Bill Summery").Select
 Range("A2:B2").Select

 ActiveSheet.Paste
 Sheets("Tel 345678901").Select
 Range("J2,A2").Select
 Selection.Copy
 Sheets("Bill Summery").Select
 Range("A3:B3").Select
 ActiveSheet.Paste

 End Sub

 Sub delete_Bill_summery_0()

 'delete all rows in sheet Bill summery which have a 0 printed in column2

 Sheets("Bill Summery").Select
 Dim i As Long
 Application.ScreenUpdating = False
 For i = Cells(Rows.Count, 2).End(xlUp).Row To 1 Step -1
  If Cells(i, 2) = "0" Then Rows(i).Delete
  Next i
 End Sub


 Option Explicit

 Sub MakeMultipleXLSfromWB()



 'Split worksheets in current workbook into
 ' many separate workbooks  D.McRitchie, 2004-06-12
 'Close each module  AND the VBE before running to save time
 ' provides a means of seeing how big sheets really are
 'Hyperlinks and formulas pointing to other worksheets within
 ' the original workbook will usually be unuseable in the new workbooks.
  Dim CurWkbook As Workbook
 Dim wkSheet As Worksheet
 Dim newWkbook As Workbook
 Dim wkSheetName As String
 Dim shtcnt(3) As Long
 Dim xpathname As String, dtimestamp As String
 dtimestamp = Format(Now, "yyyymmdd_hhmmss")
 'change the directory
 xpathname = "G:\01_Phone_Bills\extbills\v_201212\D" & dtimestamp & "\"
 MkDir xpathname
 Set CurWkbook = Application.ActiveWorkbook

 shtcnt(2) = ActiveWorkbook.Sheets.Count
 Application.ScreenUpdating = False
 Application.Calculation = xlCalculationManual
 For Each wkSheet In CurWkbook.Worksheets
  shtcnt(1) = shtcnt(1) + 1
  Application.StatusBar = shtcnt(1) & "/" & shtcnt(2) & _
      "  " & wkSheet.Name
  wkSheetName = Trim(wkSheet.Name)
  If wkSheetName = Left(Application.ActiveWorkbook.Name, _
     Len(Application.ActiveWorkbook.Name) - 4) Then _
     wkSheetName = wkSheetName & "_D" & dtimestamp
  Workbooks.Add
  ActiveWorkbook.SaveAs _
     Filename:=xpathname & wkSheetName & ".xls", _
     FileFormat:=xlNormal, Password:="", _
     WriteResPassword:="", CreateBackup:=False, _
     ReadOnlyRecommended:=False
  Set newWkbook = ActiveWorkbook

  Application.DisplayAlerts = False
  newWkbook.Worksheets("sheet1").Delete
  On Error Resume Next
  newWkbook.Worksheets(wkSheet.Name).Delete
  On Error GoTo 0
  Application.DisplayAlerts = True

  CurWkbook.Worksheets(wkSheet.Name).Copy Before:=newWkbook.Sheets(1)
  'no duplicate sheet1 because they begin with "a"
  ActiveWorkbook.Save
  ActiveWorkbook.Close
 Next wkSheet
 Application.StatusBar = False      'return control to Excel
 Application.Calculation = xlCalculationAutomatic
 Application.ScreenUpdating = True
 End Sub
于 2013-01-23T08:53:23.890 回答
0

您想将这 50000 条记录拆分为单个否,然后为每个唯一的否创建一个包含所有详细信息的工作表/工作簿,然后计算成本吗?

如果是

--> 为了让它更快,我会使用 c# 并通过 ado 链接到 excel,但你说编程不是你的最佳点:D

--> 使用 vba(需要一些时间才能完成)循环遍历这些行,然后简单地将整行复制到具有电话号码名称的新工作表中。完成循环后,通过工作表并设置总和:获取成本下方的最后一个单元格并使用 setformula 输入总和。

于 2012-09-17T15:15:14.740 回答