我知道这个问题已经被问过几次了,但是我对于如何将我的列L:L的负值循环放入一个循环中感到非常困惑。我无法正常工作。我已经尝试了所有我研究过的东西。我将不胜感激。
Option Explicit
Sub Importpaymentsales()
Dim fpath As Variant
Dim wb As Excel.Workbook
Dim ws As Excel.Worksheet
Dim Text As String
On Error GoTo terminatemsg
Set wb = Excel.ActiveWorkbook
Set ws = Excel.ActiveSheet
fpath = Application.GetOpenFilename(Filefilter:="text Files(*.txt; *.txt), *.txt; *.txt", Title:="Open Prepayment Sales Report")
If fpath = False Then Exit Sub
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Text = getTextfileData(fpath)
If Len(Text) Then
ProcessData Text
AdjustDates
Else
MsgBox fpath & " is empty", vbInformation, "Import Cancelled"
Exit Sub
End If
ws.Range("J:L").Value = ws.Range("J:L").Value
ws.Range("J:L").numberformat = "#,##0.00"
ws.Range("O:Q").Value = ws.Range("O:Q").Value
ws.Range("O:Q").numberformat = "#,##0.00"
Columns.EntireColumn.AutoFit
Sheets(1).Move Before:=wb.Sheets(1)
terminatemsg:
Application.ScreenUpdating = True
Application.DisplayAlerts = True
If Err.Number <> 0 Then MsgBox Err.Number & " " & Err.Description
End Sub
Sub ProcessData(Text As String)
Dim x As Long, y As Long, z As Long
Dim data, vLine
data = Split(Text, vbCrLf)
x = 2
Range("A1:R1").Value = Array("Supplier Name", "Supplier Number", "Inv Curr Code CurCode", "Payment CurCode", "Invoice Type", "Invoice Number", "Voucher Number", "Invoice Date", "GL Date", "Invoice Amount", "Withheld Amount", "Amount Remaining", "Description", "Account Number", "Invoice in USD", "Withheld in USD", "Amt in USD", "User Name")
For y = 0 To UBound(data)
If InStr(data(y), "|") Then
vLine = Split(data(y), "|")
If Not Trim(vLine(0)) = "Supplier" Then
For z = 0 To UBound(vLine)
vLine(z) = Trim(vLine(z))
If vLine(z) Like "*.*.*.*.*.*.*.*.*.*.*.*.*.*.*" Then vLine(z) = Left(vLine(z), InStr(vLine(z), ".") + 2)
Next
Cells(x, 1).Resize(1, UBound(vLine) + 1).Value = vLine
x = x + 1
'Range("L2:L").Value = Range("L2:L").Value * (-1)
Range("L2:L").Value = Abs(rng.Offset(teller - 1, -2).Value) * -1
End If
End If
Next
End Sub
试试这个:
Dim r As Range
For Each r In Range(Range("L2"), Range("L2").End(xlDown))
If IsNumeric(r.Value) Then r.Value = -Abs(r.Value)
Next
ps:我想您在L列之间没有空白单元格,如果这样做,则需要进行一些修改。
这里是:
Dim r As Range
For Each r In Range(Range("L2"), Range("L" & Rows.Count).End(xlUp))
If Not IsEmpty(r.Value) Then If IsNumeric(r.Value) Then r.Value = -Abs(r.Value)
Next
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句