Har forsøgt mig med lidt VBA, kontruktiv kritik modtages gerne...;-)
Sub SkildVedTal()
Dim A, B, C, D, E, F, G, H, I, J, K As Integer
Dim VP, LP, MP As String
For K = 1 To Ark1.Range("A5").End(xlUp).Row
Cells(K, 1).Select
If InStr(1, ActiveCell.Text, 1) > 0 Then
A = InStr(1, ActiveCell.Text, 1)
Else
A = 999
End If
If InStr(1, ActiveCell.Text, 2) > 0 Then
B = InStr(1, ActiveCell.Text, 2)
Else
B = 999
End If
If InStr(1, ActiveCell.Text, 3) > 0 Then
C = InStr(1, ActiveCell.Text, 3)
Else
C = 999
End If
If InStr(1, ActiveCell.Text, 4) > 0 Then
D = InStr(1, ActiveCell.Text, 4)
Else
D = 999
End If
If InStr(1, ActiveCell.Text, 5) > 0 Then
E = InStr(1, ActiveCell.Text, 5)
Else
E = 999
End If
If InStr(1, ActiveCell.Text, 6) > 0 Then
F = InStr(1, ActiveCell.Text, 6)
Else
F = 999
End If
If InStr(1, ActiveCell.Text, 7) > 0 Then
G = InStr(1, ActiveCell.Text, 7)
Else
G = 999
End If
If InStr(1, ActiveCell.Text, 8) > 0 Then
H = InStr(1, ActiveCell.Text, 8)
Else
H = 999
End If
If InStr(1, ActiveCell.Text, 9) > 0 Then
I = InStr(1, ActiveCell.Text, 9)
Else
I = 999
End If
If InStr(1, ActiveCell.Text, 0) > 0 Then
J = InStr(1, ActiveCell.Text, 0)
Else
J = 999
End If
minval = Application.WorksheetFunction.Min(A, B, C, D, E, F, G, H, I, J)
VP = Range("A" & K)
LP = Left(VP, minval - 1)
MP = Mid(VP, minval, Len(VP))
ActiveCell.Offset(0, 1).Value = LP
ActiveCell.Offset(0, 2).Value = MP
Next
End Sub
et lille eksempel (nested if loop):
gl Landevej 23
Landevejen 23
Landevej 23A
vil give:
23
23
23A
jeg har kun sat den op til at virke med en celle (adr. står i A1, resultat skrives i B1), og kun hvis tallet står til sidst.. dette er kun et lille eksempel til at sætte dig på den rette vej, dog det kan blive rodet hvis der bliver for mange tjek..
nested if loop example:
--
Dim str, strNum As String
str = ThisWorkbook.Sheets(1).Cells.Range("A1")
strNum = Mid(str, Len(str), 1)
If (IsNumeric(Mid(str, (Len(str) - 1), 1))) Then
strNum = Mid(str, (Len(str) - 1), 2)
If (IsNumeric(Mid(str, (Len(str) - 2), 1))) Then
strNum = Mid(str, (Len(str) - 2), 3)
If (IsNumeric(Mid(str, (Len(str) - 3), 1))) Then
strNum = Mid(str, (Len(str) - 3), 4)
End If
End If
End If
ThisWorkbook.Sheets(1).Cells.Range("B1") = strNum
--