Saltar al contenido
View in the app

A better way to browse. Learn more.

Ayuda Excel

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.

Redondear código

publicado

Hola buenas tardes a todos. He estado buscando y no he encontrado nada sobre ello. Vereis tengo un código VBA para que me indique un número con 3 cifras significativas (ojo no 3 decimales). Por ejmplo:

123

65.1

8.89

0.235

0.0457

etc

El código es el siguiente:

Sub Macro2()

Range("b2").Select

While Not IsEmpty(ActiveCell)

cifra = ActiveCell.Value

a = 0

i = 0

While (a = 0 Or a = ",")

i = i + 1

a = Mid(cifra, i, 1)

Wend

If i = 1 Then

If InStr(1, Mid(cifra, 1, 3), ",", vbBinaryCompare) Then

cifra = Left(cifra, 4)

Else

cifra = Left(cifra, 3)

End If

Else

cifra = Left(cifra, 2 + i)

End If

ActiveCell.Offset(1, 0).Value = cifra + 0

ActiveCell.Offset(0, 1).Select

Wend

End Sub

Ahora bien lo que ocurre es que necesito redondear a la alza cuando la cuarta cifra es mayor de 5. Por ejemplo

0.23475 sería 0.235.

¿Me podríais indicar que habría que añadir?

Eso por un lado y por otro cuando la 3a cifra es 0, solo me quedan dos cifras es decir:

56.02 me lo expresa como 56, y no como 56.0.

Si conoceis alguna manera más sencilla de conseguir esto estoy abierto a opiniones.

Muchas gracias,

Saludos a todos.

Featured Replies

No hay posts para mostrar

Archivado

Este tema está ahora archivado y está cerrado a más respuestas.

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.