Goedemiddag,
Ik heb een excel waarbij ik een aantal kolommen negatief wil maken.
Het excelbestand wordt bewerkt via vba. In eerste instantie heb ik de kolommen inderdaad negatief gekregen, maar dit was alleen de weergave. Excel rekende niet met het negatieve getal.
Dit heb ik gedaan met: Columns(item).NumberFormat = "-#,##0.00;-#,##0.00;0"
heeft iemand de oplossing voor mij?
Dit is mijn volledige macro.
Alvast bedankt
De krant
Sub M_snb()
Dim item As Integer, item2 As Integer, item3 As Integer
rownumber = 1
Dim rng As Range
rcount = ThisWorkbook.Worksheets(1).UsedRange.Rows.Count
Do
Range("b1").Offset(rownumber).Select
If ActiveCell = "" Then
ActiveCell.EntireRow.Delete
rcount = rcount - 1
Else
rownumber = rownumber + 1
End If
Loop Until rownumber = rcount
Set rng = ActiveSheet.Range("A1:bx1")
item = Application.WorksheetFunction.Match("erni", rng, 0) + 1
Cells(1, item).EntireColumn.Insert
Cells(1, item - 1).EntireColumn.Copy Destination:=Cells(1, item)
Cells(item) = "erNI Balans"
Cells(item).EntireColumn.Select
item2 = Application.WorksheetFunction.Match("standard life (Er)", rng, 0) + 1
Cells(1, item2).EntireColumn.Insert
Cells(1, item2 - 1).EntireColumn.Copy Destination:=Cells(1, item2)
Cells(item2) = "Standard life (Er) Balans"
Cells(item2).EntireColumn.Select
item3 = Application.WorksheetFunction.Match("Pension sacrifice (Er)", rng, 0) + 1
Cells(1, item3).EntireColumn.Insert
Cells(1, item3 - 1).EntireColumn.Copy Destination:=Cells(1, item3)
Cells(item3) = "Pension sacrifice(Er) Balans"
Cells(item3).EntireColumn.Select
item15 = Application.WorksheetFunction.Match("RSU compensation value", rng, 0) + 1
Cells(1, item15).EntireColumn.Insert
Cells(1, item15 - 1).EntireColumn.Copy Destination:=Cells(1, item15)
Cells(item15) = "RSU compensation"
Cells(item15).EntireColumn.Select
item4 = Application.WorksheetFunction.Match("Netpay", rng, 0)
item5 = Application.WorksheetFunction.Match("tax", rng, 0)
item6 = Application.WorksheetFunction.Match("standard life", rng, 0)
item7 = Application.WorksheetFunction.Match("NI", rng, 0)
item8 = Application.WorksheetFunction.Match("PPP", rng, 0)
item9 = Application.WorksheetFunction.Match("mileage deduction", rng, 0)
item10 = Application.WorksheetFunction.Match("studentloan", rng, 0)
item11 = Application.WorksheetFunction.Match("espp", rng, 0)
item12 = Application.WorksheetFunction.Match("car allowance net deducti", rng, 0)
item13 = Application.WorksheetFunction.Match("advance recovery", rng, 0)
item14 = Application.WorksheetFunction.Match("childcare vouchers", rng, 0)
item16 = Application.WorksheetFunction.Match("Pension sacrifice(Er) Balans", rng, 0)
item17 = Application.WorksheetFunction.Match("Standard life (Er) Balans", rng, 0)
Columns(item).NumberFormat = "-#,##0.00;-#,##0.00;0"
Columns(item2).NumberFormat = "-#,##0.00;-#,##0.00;0"
Columns(item4).NumberFormat = "-#,##0.00;-#,##0.00;0"
icol = Cells(1, Columns.Count).End(xlToLeft).Column
For x = icol To 1 Step -1
If Cells(1, x).Value = "RunDate" Then Cells(1, x).EntireColumn.Delete
If Cells(1, x).Value = "Forename" Then Cells(1, x).EntireColumn.Delete
If Cells(1, x).Value = "Surname" Then Cells(1, x).EntireColumn.Delete
If Cells(1, x).Value = "CostCentre" Then Cells(1, x).EntireColumn.Delete
If Cells(1, x).Value = "Status" Then Cells(1, x).EntireColumn.Delete
If Cells(1, x).Value = "TaxCode" Then Cells(1, x).EntireColumn.Delete
If Cells(1, x).Value = "NILetter" Then Cells(1, x).EntireColumn.Delete
If Cells(1, x).Value = "SSP" Then Cells(1, x).EntireColumn.Delete
If Cells(1, x).Value = "SMP" Then Cells(1, x).EntireColumn.Delete
If Cells(1, x).Value = "SAP" Then Cells(1, x).EntireColumn.Delete
If Cells(1, x).Value = "SPPA" Then Cells(1, x).EntireColumn.Delete
If Cells(1, x).Value = "SPPB" Then Cells(1, x).EntireColumn.Delete
If Cells(1, x).Value = "GUStudentLoan" Then Cells(1, x).EntireColumn.Delete
If Cells(1, x).Value = "GUNIReduction" Then Cells(1, x).EntireColumn.Delete
If Cells(1, x).Value = "TaxablePay" Then Cells(1, x).EntireColumn.Delete
If Cells(1, x).Value = "BIK" Then Cells(1, x).EntireColumn.Delete
If Cells(1, x).Value = "Dept" Then Cells(1, x).EntireColumn.Delete
If Cells(1, x).Value = "ESPP Percentage (%)" Then Cells(1, x).EntireColumn.Delete
If Cells(1, x).Value = "ESPP Percentage (Rate)" Then Cells(1, x).EntireColumn.Delete
If Cells(1, x).Value = "ESPP Percentage" Then Cells(1, x).EntireColumn.Delete
If Cells(1, x).Value = "AEO" Then Cells(1, x).EntireColumn.Delete
Next
sn = [origineel!A1].CurrentRegion
ReDim sp((UBound(sn) - 1) * (UBound(sn, 2) - 1), 2)
For j = 0 To UBound(sp) - 1
x = j \ (UBound(sn, 2) - 1) + 2
y = j Mod (UBound(sn, 2) - 1) + 2
sp(j, 0) = sn(x, 1)
sp(j, 1) = sn(1, y)
sp(j, 2) = sn(x, y)
Next
[bewerkt!A1].Resize(UBound(sp) + 1, UBound(sp, 2) + 1) = sp
End Sub
[/SIZE][/FONT]
Ik heb een excel waarbij ik een aantal kolommen negatief wil maken.
Het excelbestand wordt bewerkt via vba. In eerste instantie heb ik de kolommen inderdaad negatief gekregen, maar dit was alleen de weergave. Excel rekende niet met het negatieve getal.
Dit heb ik gedaan met: Columns(item).NumberFormat = "-#,##0.00;-#,##0.00;0"
heeft iemand de oplossing voor mij?
Dit is mijn volledige macro.
Alvast bedankt
De krant
Sub M_snb()
Dim item As Integer, item2 As Integer, item3 As Integer
rownumber = 1
Dim rng As Range
rcount = ThisWorkbook.Worksheets(1).UsedRange.Rows.Count
Do
Range("b1").Offset(rownumber).Select
If ActiveCell = "" Then
ActiveCell.EntireRow.Delete
rcount = rcount - 1
Else
rownumber = rownumber + 1
End If
Loop Until rownumber = rcount
Set rng = ActiveSheet.Range("A1:bx1")
item = Application.WorksheetFunction.Match("erni", rng, 0) + 1
Cells(1, item).EntireColumn.Insert
Cells(1, item - 1).EntireColumn.Copy Destination:=Cells(1, item)
Cells(item) = "erNI Balans"
Cells(item).EntireColumn.Select
item2 = Application.WorksheetFunction.Match("standard life (Er)", rng, 0) + 1
Cells(1, item2).EntireColumn.Insert
Cells(1, item2 - 1).EntireColumn.Copy Destination:=Cells(1, item2)
Cells(item2) = "Standard life (Er) Balans"
Cells(item2).EntireColumn.Select
item3 = Application.WorksheetFunction.Match("Pension sacrifice (Er)", rng, 0) + 1
Cells(1, item3).EntireColumn.Insert
Cells(1, item3 - 1).EntireColumn.Copy Destination:=Cells(1, item3)
Cells(item3) = "Pension sacrifice(Er) Balans"
Cells(item3).EntireColumn.Select
item15 = Application.WorksheetFunction.Match("RSU compensation value", rng, 0) + 1
Cells(1, item15).EntireColumn.Insert
Cells(1, item15 - 1).EntireColumn.Copy Destination:=Cells(1, item15)
Cells(item15) = "RSU compensation"
Cells(item15).EntireColumn.Select
item4 = Application.WorksheetFunction.Match("Netpay", rng, 0)
item5 = Application.WorksheetFunction.Match("tax", rng, 0)
item6 = Application.WorksheetFunction.Match("standard life", rng, 0)
item7 = Application.WorksheetFunction.Match("NI", rng, 0)
item8 = Application.WorksheetFunction.Match("PPP", rng, 0)
item9 = Application.WorksheetFunction.Match("mileage deduction", rng, 0)
item10 = Application.WorksheetFunction.Match("studentloan", rng, 0)
item11 = Application.WorksheetFunction.Match("espp", rng, 0)
item12 = Application.WorksheetFunction.Match("car allowance net deducti", rng, 0)
item13 = Application.WorksheetFunction.Match("advance recovery", rng, 0)
item14 = Application.WorksheetFunction.Match("childcare vouchers", rng, 0)
item16 = Application.WorksheetFunction.Match("Pension sacrifice(Er) Balans", rng, 0)
item17 = Application.WorksheetFunction.Match("Standard life (Er) Balans", rng, 0)
Columns(item).NumberFormat = "-#,##0.00;-#,##0.00;0"
Columns(item2).NumberFormat = "-#,##0.00;-#,##0.00;0"
Columns(item4).NumberFormat = "-#,##0.00;-#,##0.00;0"
icol = Cells(1, Columns.Count).End(xlToLeft).Column
For x = icol To 1 Step -1
If Cells(1, x).Value = "RunDate" Then Cells(1, x).EntireColumn.Delete
If Cells(1, x).Value = "Forename" Then Cells(1, x).EntireColumn.Delete
If Cells(1, x).Value = "Surname" Then Cells(1, x).EntireColumn.Delete
If Cells(1, x).Value = "CostCentre" Then Cells(1, x).EntireColumn.Delete
If Cells(1, x).Value = "Status" Then Cells(1, x).EntireColumn.Delete
If Cells(1, x).Value = "TaxCode" Then Cells(1, x).EntireColumn.Delete
If Cells(1, x).Value = "NILetter" Then Cells(1, x).EntireColumn.Delete
If Cells(1, x).Value = "SSP" Then Cells(1, x).EntireColumn.Delete
If Cells(1, x).Value = "SMP" Then Cells(1, x).EntireColumn.Delete
If Cells(1, x).Value = "SAP" Then Cells(1, x).EntireColumn.Delete
If Cells(1, x).Value = "SPPA" Then Cells(1, x).EntireColumn.Delete
If Cells(1, x).Value = "SPPB" Then Cells(1, x).EntireColumn.Delete
If Cells(1, x).Value = "GUStudentLoan" Then Cells(1, x).EntireColumn.Delete
If Cells(1, x).Value = "GUNIReduction" Then Cells(1, x).EntireColumn.Delete
If Cells(1, x).Value = "TaxablePay" Then Cells(1, x).EntireColumn.Delete
If Cells(1, x).Value = "BIK" Then Cells(1, x).EntireColumn.Delete
If Cells(1, x).Value = "Dept" Then Cells(1, x).EntireColumn.Delete
If Cells(1, x).Value = "ESPP Percentage (%)" Then Cells(1, x).EntireColumn.Delete
If Cells(1, x).Value = "ESPP Percentage (Rate)" Then Cells(1, x).EntireColumn.Delete
If Cells(1, x).Value = "ESPP Percentage" Then Cells(1, x).EntireColumn.Delete
If Cells(1, x).Value = "AEO" Then Cells(1, x).EntireColumn.Delete
Next
sn = [origineel!A1].CurrentRegion
ReDim sp((UBound(sn) - 1) * (UBound(sn, 2) - 1), 2)
For j = 0 To UBound(sp) - 1
x = j \ (UBound(sn, 2) - 1) + 2
y = j Mod (UBound(sn, 2) - 1) + 2
sp(j, 0) = sn(x, 1)
sp(j, 1) = sn(1, y)
sp(j, 2) = sn(x, y)
Next
[bewerkt!A1].Resize(UBound(sp) + 1, UBound(sp, 2) + 1) = sp
End Sub
[/SIZE][/FONT]