Liebe/-r Experte/-in,
Hallo Michael,
ich bin VBA ANfaenger und hatte gehofft du koenntest mir vllt weiterhelfen Ich arbeite gerade an einem Sheet wo ich einfach nicht weiterkomme. Ein Kleiner Ausschnitt:
http://db.tt/E24yZLC
DIe Daten werden automatisch aus eine Quelle in bestimmten Zeitabstaenden geholt. Ich wollte nun zwei Spalten (AS und AT) hinzufuegen. AS soll prufen welche Werte in Spalte I stehen. Zusaetzlich pruft AT den Wert aus Spalte B.
Zum Beispiel:
a)I Saplte (Dep Name) enthaelt Substring LOG (waere z.B der Fall bei βPS/LOG1-DEβ), dann βFCβ in AS eintragen
b)Wenn a) is true dann Costnr (Spalte B)pruefen, faengt es mit 4 an dann wird CI in SPalte AT eingetragen.
Leider traegt er bei mir die Werte nicht in die Zellen, ich habe aber noch nicht rausgefunden warum. Meine Vermutung entwerder die Logik der If SChleife stimmt nicht oder liegt es an der Substring suche, kann man das so machen mit den Sternchen?
Ich wuerde mich ueber jeglichen Tipp freuen. vielen dank!
Sub calc()
'Definition of Columns Sheet1
CostCtr = Worksheets("Sheet1").Range("B:B").Column
DepName = Worksheets("Sheet1").Range("I:I").Column
TypeOfWork = Worksheets("Sheet1").Range("K:K").Column
DepToCostCenter = Worksheets("Sheet1").Range("AS:AS").Column
NewDepName = Worksheets("Sheet1").Range("AT:AT").Column
Const Sheet1\_BORDER\_R\_TOP = 21
Const Sheet1\_BORDER\_R\_BOTTOM = 5000
For j = Sheet1\_BORDER\_R\_TOP To Sheet1\_BORDER\_R\_BOTTOM 'Zeilen sheet1
see\_costCtr = Worksheets("Sheet1").Cells(j, CostCtr).Value
see\_DepName = Worksheets("Sheet1").Cells(j, DepName).Value
see\_TypeOfWork = Worksheets("Sheet1").Cells(j, TypeOfWork).Value
write\_DepToCostCenter = Worksheets("Sheet1").Cells(j, DepToCostCenter).Value
write\_newDepNames = Worksheets("Sheet1").Cells(j, NewDepName).Value
If (see\_DepName = "\*" & "Log\*" & "\*" Or see\_DepName = "\*" & "PU" & "\*" Or see\_DepName = "\*" & "\*CL\*" & "\*" Or see\_DepName = "\*" & "\*CFA\*" & "\*" Or see\_DepName = "\*" & "\*FCM\*" & "\*") Then 'All FC related Departments
write\_newDepNames = "FC"
ElseIf (see\_DepName = "\*" & "\*/S\*" & "\*" Or see\_DepName = "\*" & "\*/MKL\*" & "\*" Or see\_DepName = "\*" & "\*COV\*" & "\*") Then 'All SA related Departments
write\_newDepNames = "SA"
ElseIf (see\_DepName = "\*" & "\*/QM\*" & "\*") Then 'All QM related Departments
write\_newDepNames = "QM"
ElseIf (see\_DepName = "\*" & "\*/MS\*" & "\*" Or see\_DepName = "\*" & "\*/MF\*" & "\*" Or see\_DepName = "\*" & "\*/TEF\*" & "\*" Or see\_DepName = "\*" & "HRL\*" & "\*" Or see\_DepName = "\*" & "\*/MO\*" & "\*" Or see\_DepName = "\*" & "\*/PER\*" & "\*" Or see\_DepName = "\*" & "\*/ADM\*" & "\*" Or see\_DepName = "\*" & "\*BPS\*" & "\*") Then 'All MG related Departments
write\_newDepNames = "MG"
ElseIf (see\_DepName = "\*" & "\*/COS\*" & "\*" Or see\_DepName = "\*" & "\*/E\*" & "\*" Or see\_DepName = "\*" & "\*-E\*" & "\*" Or see\_DepName = "\*" & "\*/NE\*" & "\*") Then 'All NE related Departments
write\_newDepNames = "NE"
ElseIf (see\_DepName = "\*" & "\*/ORG\*" & "\*" Or see\_DepName = "\*" & "\*ICO\*" & "\*") Then 'All ORG
write\_newDepNames = "ORG"
Else 'All Other Departments
write\_newDepNames = "Other"
If (Left(see\_costCtr, 1) = 4) Then 'Checks if CostCenterNr begins with 4, all "CI" related Departments
write\_DepToCostCenter.Value = "CI1"
ElseIf (see\_costCtr = "\*" & "028C01" & "\*") Then 'Checks if CostCenterNr begins with 208C01 all "CI/ISY" related Departments
write\_DepToCostCenter = "CI/ISY"
ElseIf (see\_costCtr = "\*" & "028C05" & "\*") Then 'Checks if CostCenterNr begins with 208C05, all "CI/NER" related Departments
write\_DepToCostCenter = "C2/NER"
Else 'all other numbers
write\_DepToCostCenter = "CI/2"
End If
End If
Next
End Sub