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.

[VBA] Format klappt nicht

Empfohlene Antworten

Veröffentlicht

Hallo,

Ich möchte Werte aus einer Tabelle auslesen und diese dann getrennt (nach vollen Euros und Cent) in 2 Zellen schreiben

jetzt hab ich aber das Problem, dass wenn ich eine 1 dezimalstellige Zahl in meiner Variable habe, immer das Komma mitgeschrieben wird...


        Dim dGes As Double

        dGes = Format(dGes, "###0.00")

        .Tables(2).Cell(7, 2).Select

        Selection.Text = CStr(CInt(dGes))

        .Tables(2).Cell(7, 4).Select

        Selection.Text = Right(CStr(dGes), 2)

Warum geht das nicht ?!

Right(CStr(dGes), 2)

du wandelst den zellinhalt in string um und nimmst immer die letzten zwei stellen, klar dass da bei werten mit einer, drei oder mehr nachkommastellen der falsche wert rauskommt.

versuchs mal mit

Mid(CStr(Round(dGes- Fix(dGes), 3)), 3,2)

s'Amstel

  • Autor

nein, dGes ist das Ges-amte Endergebnis (double)

Da werden auch die Daten korrekt eingetragen - nur hatte der wahrscheinlich Probleme, weil die zweite Kommastelle eine 0 ist.

Hab das mit debuggen probiert - da kam, dass dGes 100,5 wäre - Format(dGes, "###0.00") hatte "100,50" zurückgeliefert aber danach war es immernoch 100,5 O.o

hab das jetzt so gemacht:


        .Tables(2).Cell(7, 2).Select

        Selection.Text = CStr(CInt(dGes))

        .Tables(2).Cell(7, 4).Select

        Selection.Text = Right(CStr(Format(dGes, "###0.00")), 2)

geht trotzdem *g*

aber deine Lösung merk ich mir mal ;)

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.