Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Inhalt mit VBA auslesen

Empfohlene Antworten

Veröffentlicht

Hallo zusammen,

ich habe in einer Excel-Zelle unterschiedlichste Zahlen stehen (z.B. 810/81/114 088 2, - 05.05.2006, 1024-06-0000-06275). Nun möchte ich gerne die Zahlen - von links - bis zum ersten Komma haben. Eventuelle aber auch mal von rechts bis zum ersten Komma oder den Mittelteil.

Kennt jemand den Code???

Schaust du hier: http://www.excelformeln.de/formeln.html?welcher=101

ganz ohne VBA, falls das hilft is zwar etwas anders als deine Aufgabe aber lässt sich sicher anpassen denk ich.

Warum eigentlich alle diese Werte in einer Zelle?

  • Autor

Hallo,

vielen Dank für die Antwort. Diese Werte stehen in einer Zelle, weil das Programm - aus dem ich die Daten gezogen habe - diese so liefert. Nun sollen Sie in Exel weiter bearbeitet werden.

Ich würde es trotzdem gerne mit VBA lösen, da ich diese Zahlen dann noch weiter verarbeiten muss. Das ist dann mit VBA einfacher.

Veruch es mal so:

Dim x As Integer

Dim zahlen As String

x = InStr(Range("b5").Value, ",")

zahlen = Mid(Range("b5").Value, 1, x - 1)

InStr(zu dursuchender String, gesuchter String) gibt die Anfangsposition eines Strings (hier das Komma) innerhalb eines Strings (also der Zelleninhalt) wieder. Mit Mid(String,Start,Ende) kannst du dann in diesem Beispiel die Zeichen von Position 1 bis eine Position vor dem Komma auslesen. alternativ ginge auch

Left(Range("b5").Value, x-1). Left liest dann x-1 zeichen von links nach rechts, es gibt natürlich auch Right(..., ...)

Hilft Dir das weiter?

Gruß

Gordonski

Du müsstest auf die Variable "strCell" dynamisch die Excel-Zelle schreiben.


Dim strCell

Dim strValue

Dim lngKommaFound

'Von Links bis zum ersten Komma

strCell = "810/81/114 088 2, - 05.05.2006, 1024-06-0000-06275"

lngKommaFound = InStr(1, strCell, ",")

strValue = Mid(strCell, 1, lngKommaFound - 1)

MsgBox strValue


'Von Links bis zum letzten Komma

strCell = "810/81/114 088 2, - 05.05.2006, 1024-06-0000-06275"

lngKommaFound = DV_InStrRight(strCell, ",")

strValue = Mid(strCell, 1, lngKommaFound - 1)

MsgBox strValue


'Von Rechts bis zum ersten Komma

strCell = "810/81/114 088 2, - 05.05.2006, 1024-06-0000-06275"

lngKommaFound = DV_InStrRight(strCell, ",")

strValue = Mid(strCell, lngKommaFound + 1)

MsgBox strValue


'Von Rechts bis zum letzten Komma

strCell = "810/81/114 088 2, - 05.05.2006, 1024-06-0000-06275"

lngKommaFound = DV_InStrRight(strCell, ",")

strValue = Mid(strCell, 1, lngKommaFound - 1)

MsgBox strValue


'Von Links dem ersten Komma bis Rechts dem ersten Komma

Dim lngKommaFoundLinks

Dim lngKommaFoundRechts

strCell = "810/81/114 088 2, - 05.05.2006, 1024-06-0000-06275"

lngKommaFoundLinks = InStr(1, strCell, ",")

lngKommaFoundRechts = DV_InStrRight(strCell, ",")

strValue = Mid(strCell, 1, lngKommaFoundRechts - 1)

strValue = Mid(strValue, lngKommaFoundLinks + 1)

MsgBox strValue



Private Function DV_InStrRight(strQuelle, strSuche)

    Dim intPos

    If Not (IsNull(strQuelle) Or IsNull(strSuche)) Then

        intPos = InStr(strQuelle, strSuche)

        Do While intPos > 0

            DV_InStrRight = intPos

            intPos = InStr(intPos + 1, strQuelle, strSuche)

        Loop

    End If

End Function

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.