Enviar decimales de listbox a hoja de exel

Soy nuevo en este tema, y estoy trababajando en un archivo que fui adaptando de distintos expertos en la red. Se trata de un listbox al cual cuando paso los datos a una hoja me pasa como enteros los decimales ya he probado distintas formatos desde vba y no me coincide lo que muestra el listbox con dato copiado en hoja. Ayuda

2 Respuestas

Respuesta
2

Intente con Val como este ejemplo

Val(ListBox1.List(i, 1))

Buenas tardes Dante, primero muchas gracias por tu atención, mira he probado lo arriba descrito y me da error, no alcanza a correr el formulario. reduje el archivo para poder subirlo sin problemas, la idea seria que los valores del Reporte  tome el mismo formato (decimal) que la hoja Datos para que pueda realizar el gráfico desde VBA ya definido, el tema es que si el numero es 0,xxxx lo toma bien pero si es 1,XXXXX escribe otro formato, llevo tiempo ya probando distintos Format  y lo que se escribe bien en hoja reporte se ve mal en listbox y viceversa. 

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
On Error GoTo Fin
If CloseMode <> 1 Then Cancel = True
Fin:
End Sub
Public Sub UserForm_Initialize()
Application.DisplayAlerts = False
Application.ScreenUpdating = True
End Sub
Private Sub TextBox2_AfterUpdate()
TextBox2 = Format(TextBox2, "dd/mm/yyYY")
End Sub
Private Sub TextBox3_AfterUpdate()
TextBox3 = Format(TextBox3, "dd/mm/yy")
End Sub
Private Sub buscar_Click()
Sheets("Datos").Unprotect "lolita2020"
Sheets("Datos").Range("EH15") = Nmedidor.Text
   If Trim(Nmedidor.Text) = "" Then
        MsgBox "Seleccione un medidor", vbExclamation, "AVISO"
        Nmedidor.SetFocus
         Exit Sub
        ElseIf Trim(Nmedidor.Text) < 1 Then
        MsgBox "Seleccione un medidor del 1 al 4", vbInformation, "AVISO"
         Nmedidor = ""
         Nmedidor.SetFocus
Exit Sub
  ElseIf Trim(Nmedidor.Text) > 4 Then
  MsgBox "Seleccione un medidor del 1 al 4", vbInformation, "AVISO"
         Nmedidor = ""
         Nmedidor.SetFocus
         Exit Sub
End If
ThisWorkbook.Sheets("Datos").activate
Sheets("Datos").Unprotect "lolita2020"
Sheets("Datos").Range("FD10") = Nmedidor.Text
 If Trim(Nmedidor.Text) = 1 Then
On Error Resume Next
Set b = Sheets("Datos")
uf = b.Range("EH" & Rows.Count).End(xlUp).Row
dato1 = CDate(TextBox2)
dato2 = CDate(TextBox3)
If dato2 = Empty Or dato1 = emtpy Then
MsgBox ("Debe ingresar datos para consulta entre rango de fechas"), vbCritical, "AVISO"
Exit Sub
End If
If dato2 < dato1 Then
MsgBox ("La fecha final no puede ser mayor a la fecha inicial"), vbCritical, "AVISO"
Exit Sub
End If
b.AutoFilterMode = False
Me.ListBox1 = Clear
Me.ListBox1.RowSource = Clear
'Adiciona un item al listbox reservado para la cabecera
InfoCarta.ListBox1.AddItem
InfoCarta.ListBox1.AddItem
For i = 21 To uf
   dato0 = CDate(b.Cells(i, 138).Value)
   If dato0 >= dato1 And dato0 <= dato2 Then
       Me.ListBox1.AddItem b.Cells(i, 138)                                 ' Fecha
       Me.ListBox1.List(Me.ListBox1.ListCount - 1, 1) = b.Cells(i, 137)   ' Reporte
       Me.ListBox1.List(Me.ListBox1.ListCount - 1, 2) = b.Cells(i, 144) ' Meter Factor
       Me.ListBox1.List(Me.ListBox1.ListCount - 1, 3) = b.Cells(i, 143)  ' Densidad
       Me.ListBox1.List(Me.ListBox1.ListCount - 1, 4) = b.Cells(i, 162)  ' Advertencia Sup
       Me.ListBox1.List(Me.ListBox1.ListCount - 1, 5) = b.Cells(i, 163)  ' Advertencia Inf
       Me.ListBox1.List(Me.ListBox1.ListCount - 1, 6) = b.Cells(i, 164)  ' Accion Sup
       Me.ListBox1.List(Me.ListBox1.ListCount - 1, 7) = b.Cells(i, 165)  ' Accion Inf
       Me.ListBox1.List(Me.ListBox1.ListCount - 1, 8) = b.Cells(i, 166)  ' Tolerancia Sup
       Me.ListBox1.List(Me.ListBox1.ListCount - 1, 9) = b.Cells(i, 167)  ' Tolerancia Inf
'       #.0.0000
       ListBox1.List(ListBox1.ListCount - 1, 2) = Format(ListBox1.List(ListBox1.ListCount - 1, 2), " #.00000")
       ListBox1.List(ListBox1.ListCount - 1, 4) = Format(ListBox1.List(ListBox1.ListCount - 1, 4), "#.00000")
       ListBox1.List(ListBox1.ListCount - 1, 5) = Format(ListBox1.List(ListBox1.ListCount - 1, 5), "#.00000")
       ListBox1.List(ListBox1.ListCount - 1, 6) = Format(ListBox1.List(ListBox1.ListCount - 1, 6), "#.00000")
       ListBox1.List(ListBox1.ListCount - 1, 7) = Format(ListBox1.List(ListBox1.ListCount - 1, 7), "#.00000")
       ListBox1.List(ListBox1.ListCount - 1, 8) = Format(ListBox1.List(ListBox1.ListCount - 1, 8), "#.00000")
       ListBox1.List(ListBox1.ListCount - 1, 9) = Format(ListBox1.List(ListBox1.ListCount - 1, 9), "#.00000")
       Me.ListBox1.RowSource = True
   End If
Next i
    ElseIf Trim(Nmedidor.Text) = 2 Then
    On Error Resume Next
Set b = Sheets("Datos")
uf = b.Range("FV" & Rows.Count).End(xlUp).Row
dato1 = CDate(TextBox2)
dato2 = CDate(TextBox3)
If dato2 = Empty Or dato1 = emtpy Then
MsgBox ("Debe ingresar datos para consulta entre rango de fechas"), vbCritical, "AVISO"
Exit Sub
End If
If dato2 < dato1 Then
MsgBox ("La fecha final no puede ser mayor a la fecha inicial"), vbCritical, "AVISO"
Exit Sub
End If
b.AutoFilterMode = False
Me.ListBox1 = Clear
Me.ListBox1.RowSource = Clear
'Adiciona un item al listbox reservado para la cabecera
InfoCarta.ListBox1.AddItem
InfoCarta.ListBox1.AddItem
For i = 21 To uf
   dato0 = CDate(b.Cells(i, 178).Value)
   If dato0 >= dato1 And dato0 <= dato2 Then
       Me.ListBox1.AddItem b.Cells(i, 178)                                 ' Fecha
       Me.ListBox1.List(Me.ListBox1.ListCount - 1, 1) = b.Cells(i, 177)   ' Reporte
       Me.ListBox1.List(Me.ListBox1.ListCount - 1, 2) = b.Cells(i, 184)  ' Meter Factor
       Me.ListBox1.List(Me.ListBox1.ListCount - 1, 3) = b.Cells(i, 183)  ' densidad
       Me.ListBox1.List(Me.ListBox1.ListCount - 1, 4) = b.Cells(i, 202)  ' Advertencia Sup
       Me.ListBox1.List(Me.ListBox1.ListCount - 1, 5) = b.Cells(i, 203)  ' Advertencia Inf
       Me.ListBox1.List(Me.ListBox1.ListCount - 1, 6) = b.Cells(i, 204)  ' Accion Sup
       Me.ListBox1.List(Me.ListBox1.ListCount - 1, 7) = b.Cells(i, 205)  ' Accion Inf
       Me.ListBox1.List(Me.ListBox1.ListCount - 1, 8) = b.Cells(i, 206)  ' Tolerancia Sup
       Me.ListBox1.List(Me.ListBox1.ListCount - 1, 9) = b.Cells(i, 207)  ' Tolerancia Inf
       ListBox1.List(ListBox1.ListCount - 1, 4) = Format(ListBox1.List(ListBox1.ListCount - 1, 4), "0.00000")
       ListBox1.List(ListBox1.ListCount - 1, 5) = Format(ListBox1.List(ListBox1.ListCount - 1, 5), "0.00000")
       ListBox1.List(ListBox1.ListCount - 1, 6) = Format(ListBox1.List(ListBox1.ListCount - 1, 6), "0.00000")
       ListBox1.List(ListBox1.ListCount - 1, 7) = Format(ListBox1.List(ListBox1.ListCount - 1, 7), "0.00000")
       ListBox1.List(ListBox1.ListCount - 1, 8) = Format(ListBox1.List(ListBox1.ListCount - 1, 8), "0.00000")
       ListBox1.List(ListBox1.ListCount - 1, 9) = Format(ListBox1.List(ListBox1.ListCount - 1, 9), "0.00000")
       Me.ListBox1.RowSource = True
   End If
Next i
      ElseIf Trim(Nmedidor.Text) = 3 Then
    On Error Resume Next
Set b = Sheets("Datos")
uf = b.Range("IH" & Rows.Count).End(xlUp).Row
dato1 = CDate(TextBox2)
dato2 = CDate(TextBox3)
If dato2 = Empty Or dato1 = emtpy Then
MsgBox ("Debe ingresar datos para consulta entre rango de fechas"), vbCritical, "AVISO"
Exit Sub
End If
If dato2 < dato1 Then
MsgBox ("La fecha final no puede ser mayor a la fecha inicial"), vbCritical, "AVISO"
Exit Sub
End If
b.AutoFilterMode = False
Me.ListBox1 = Clear
Me.ListBox1.RowSource = Clear
'Adiciona un item al listbox reservado para la cabecera
InfoCarta.ListBox1.AddItem
InfoCarta.ListBox1.AddItem
For i = 21 To uf
   dato0 = CDate(b.Cells(i, 217).Value)
   If dato0 >= dato1 And dato0 <= dato2 Then
       Me.ListBox1.AddItem b.Cells(i, 217)                                 ' Fecha
       Me.ListBox1.List(Me.ListBox1.ListCount - 1, 1) = b.Cells(i, 216)   ' Reporte
       Me.ListBox1.List(Me.ListBox1.ListCount - 1, 2) = b.Cells(i, 223)  ' Meter Factor
       Me.ListBox1.List(Me.ListBox1.ListCount - 1, 3) = b.Cells(i, 222)  ' Densidad
       Me.ListBox1.List(Me.ListBox1.ListCount - 1, 4) = b.Cells(i, 241)  ' Advertencia Sup
       Me.ListBox1.List(Me.ListBox1.ListCount - 1, 5) = b.Cells(i, 242)  ' Advertencia Inf
       Me.ListBox1.List(Me.ListBox1.ListCount - 1, 6) = b.Cells(i, 243)  ' Accion Sup
       Me.ListBox1.List(Me.ListBox1.ListCount - 1, 7) = b.Cells(i, 244)  ' Accion Inf
       Me.ListBox1.List(Me.ListBox1.ListCount - 1, 8) = b.Cells(i, 245)  ' Tolerancia Sup
       Me.ListBox1.List(Me.ListBox1.ListCount - 1, 9) = b.Cells(i, 246)  ' Tolerancia Inf
       ListBox1.List(ListBox1.ListCount - 1, 4) = Format(ListBox1.List(ListBox1.ListCount - 1, 4), "0.00000")
       ListBox1.List(ListBox1.ListCount - 1, 5) = Format(ListBox1.List(ListBox1.ListCount - 1, 5), "0.00000")
       ListBox1.List(ListBox1.ListCount - 1, 6) = Format(ListBox1.List(ListBox1.ListCount - 1, 6), "0.00000")
       ListBox1.List(ListBox1.ListCount - 1, 7) = Format(ListBox1.List(ListBox1.ListCount - 1, 7), "0.00000")
       ListBox1.List(ListBox1.ListCount - 1, 8) = Format(ListBox1.List(ListBox1.ListCount - 1, 8), "0.00000")
       ListBox1.List(ListBox1.ListCount - 1, 9) = Format(ListBox1.List(ListBox1.ListCount - 1, 9), "0.00000")
       Me.ListBox1.RowSource = True
   End If
Next i
 ElseIf Trim(Nmedidor.Text) = 4 Then
    On Error Resume Next
Set b = Sheets("Datos")
uf = b.Range("IV" & Rows.Count).End(xlUp).Row
dato1 = CDate(TextBox2)
dato2 = CDate(TextBox3)
If dato2 = Empty Or dato1 = emtpy Then
MsgBox ("Debe ingresar datos para consulta entre rango de fechas"), vbCritical, "AVISO"
Exit Sub
End If
If dato2 < dato1 Then
MsgBox ("La fecha final no puede ser mayor a la fecha inicial"), vbCritical, "AVISO"
Exit Sub
End If
b.AutoFilterMode = False
Me.ListBox1 = Clear
Me.ListBox1.RowSource = Clear
'Adiciona un item al listbox reservado para la cabecera
InfoCarta.ListBox1.AddItem
InfoCarta.ListBox1.AddItem
For i = 21 To uf
   dato0 = CDate(b.Cells(i, 256).Value)
   If dato0 >= dato1 And dato0 <= dato2 Then
       Me.ListBox1.AddItem b.Cells(i, 256)                                 ' Fecha
       Me.ListBox1.List(Me.ListBox1.ListCount - 1, 1) = b.Cells(i, 255)   ' Reporte
       Me.ListBox1.List(Me.ListBox1.ListCount - 1, 2) = b.Cells(i, 261)  ' Meter Factor
       Me.ListBox1.List(Me.ListBox1.ListCount - 1, 3) = b.Cells(i, 280)  ' Densidad
       Me.ListBox1.List(Me.ListBox1.ListCount - 1, 4) = b.Cells(i, 281)  ' Advertencia Sup
       Me.ListBox1.List(Me.ListBox1.ListCount - 1, 5) = b.Cells(i, 282)  ' Advertencia Inf
       Me.ListBox1.List(Me.ListBox1.ListCount - 1, 6) = b.Cells(i, 283)  ' Accion Sup
       Me.ListBox1.List(Me.ListBox1.ListCount - 1, 7) = b.Cells(i, 284)  ' Accion Inf
       Me.ListBox1.List(Me.ListBox1.ListCount - 1, 8) = b.Cells(i, 285)  ' Tolerancia Sup
       Me.ListBox1.List(Me.ListBox1.ListCount - 1, 9) = b.Cells(i, 262)  ' Tolerancia Inf
       ListBox1.List(ListBox1.ListCount - 1, 4) = Format(ListBox1.List(ListBox1.ListCount - 1, 4), "0.00000")
       ListBox1.List(ListBox1.ListCount - 1, 5) = Format(ListBox1.List(ListBox1.ListCount - 1, 5), "0.00000")
       ListBox1.List(ListBox1.ListCount - 1, 6) = Format(ListBox1.List(ListBox1.ListCount - 1, 6), "0.00000")
       ListBox1.List(ListBox1.ListCount - 1, 7) = Format(ListBox1.List(ListBox1.ListCount - 1, 7), "0.00000")
       ListBox1.List(ListBox1.ListCount - 1, 8) = Format(ListBox1.List(ListBox1.ListCount - 1, 8), "0.00000")
       ListBox1.List(ListBox1.ListCount - 1, 9) = Format(ListBox1.List(ListBox1.ListCount - 1, 9), "0.00000")
       Me.ListBox1.RowSource = True
   End If
Next i
    End If
'Carga los datos de la cabecera en listbox
For ii = 0 To 10
InfoCarta.ListBox1.List(0, ii) = Sheets("Datos").Cells(10, ii + 62)
Next ii
'Carga registra y suma columnas en listbox
InfoCarta.ListBox1.AddItem
InfoCarta.ListBox1.AddItem
InfoCarta.ListBox1.AddItem
InfoCarta.ListBox1.AddItem
InfoCarta.ListBox1.AddItem
InfoCarta.ListBox1.AddItem
InfoCarta.ListBox1.AddItem
InfoCarta.ListBox1.List(InfoCarta.ListBox1.ListCount - 5, 0) = "Total Reportes :"
'funciones matematicas
Dim tot As Single
For x = 0 To InfoCarta.ListBox1.ListCount - 1
t = CDec(InfoCarta.ListBox1.List(x, 2))
tot = tot + t
t = 0
Next x
InfoCarta.ListBox1.List(InfoCarta.ListBox1.ListCount - 5, 1) = InfoCarta.ListBox1.ListCount - 9
  Me.ListBox1.ColumnWidths = "100 pt;70 pt;90 pt;90 pt;100 pt;100 pt;100pt;100 pt;100 pt;100 pt"
  Sheets("Datos").Protect "lolita2020"
End Sub
Public Sub Graficar_Click()
On Error Resume Next
If ListBox1.ListCount = 0 Then
MsgBox ("Complete rangos de busqueda y luego Pulse la opcion buscar"), vbCritical, "AVISO"
Exit Sub
Application.ScreenUpdating = False
Application.DisplayAlerts = False
On Error Resume Next
End If
'Elimina hoja y crea hoja dando el mismo nombre que la eliminada
Sheets("Reporte").Delete
ActiveWorkbook.Sheets.Add after:=Worksheets(Worksheets.Count)
ActiveSheet.Name = "Reporte"
Set a = Sheets("Reporte")
For x = 1 To InfoCarta.ListBox1.ListCount - 7
a.Cells(x + 2, "B") = CDate(ListBox1.List(x, 0))
a.Cells(x + 2, "C") = ListBox1.List(x, 1)
a.Cells(x + 2, "D") = ListBox1.List(x, 2)
a.Cells(x + 2, "E") = ListBox1.List(x, 3)
a.Cells(x + 2, "F") = ListBox1.List(x, 4)
a.Cells(x + 2, "G") = ListBox1.List(x, 5)
a.Cells(x + 2, "H") = ListBox1.List(x, 6)
a.Cells(x + 2, "I") = ListBox1.List(x, 7)
a.Cells(x + 2, "J") = ListBox1.List(x, 8)
a.Cells(x + 2, "K") = ListBox1.List(x, 9)
Next
a.Cells(x + 3, "B") = ListBox1.List(x + 1, 0)
a.Cells(x + 3, "C") = ListBox1.List(x + 1, 1)
Dim comp As String
comp = Sheets("Datos").Range("F3")
med = Sheets("Datos").Range("EH15")
a.activate
a.Range("B1") = "CARTA DE CONTROL:" & "  " & " Medidor Nª:" & med & "  " & comp
a.Range("B2") = "Fecha"
a.Range("C2") = "Reporte"
a.Range("D2") = "Meter Factor"
a.Range("E2") = "Densidad(Kg/cm³)"
a.Range("F2") = "Advertencia Sup."
a.Range("G2") = "Advertencia Inf."
a.Range("H2") = "Accion Sup."
a.Range("I2") = "Accion Inf."
a.Range("J2") = "Tolerancia Sup."
a.Range("K2") = "Tolerancia Inf."
uf = a.Range("G" & Rows.Count).End(xlUp).Row
a.Range("B2:B" & uf).NumberFormat = "mm/dd/yy"
a.Range ("C2:C" & uf)
a.Range ("D2:D" & uf)
a.Range ("E2:E" & uf) '.NumberFormat = "000.0"
a.Range ("F2:F" & uf)
a.Range ("G2:G" & uf)
a.Range ("H2:H" & uf)
a.Range ("I2:I" & uf)
a.Range ("J2:J" & uf)
a.Range ("K2:K" & uf)
a.Range("B:K").ColumnWidth = 16
a.Range("B:K").HorizontalAlignment = xlCenter
'
'
''**********************************************************
Fila_Final = Range("B" & Cells.Rows.Count).End(xlUp).Row
Range("B4:K" & Fila_Final).Select
Dim celda As Range
For Each celda In selection
    If Not IsNumeric(celda.Value) Then
        celda.Value = WorksheetFunction.Trim(celda.Value)
    ElseIf TypeName(celda.Value) = "String" Then
        celda.Value = celda.Value + 1 - 1
    End If
Next celda
''**********************************************************
With a.Range("B2:K" & uf)
.Borders(xlEdgeLeft).LineStyle = xlContinuous
.Borders(xlEdgeLeft).Weight = xlThin
.Borders(xlEdgeTop).LineStyle = xlContinuous
.Borders(xlEdgeTop).Weight = xlThin
.Borders(xlEdgeBottom).LineStyle = xlContinuous
.Borders(xlEdgeBottom).Weight = xlThin
.Borders(xlEdgeRight).LineStyle = xlContinuous
.Borders(xlEdgeRight).Weight = xlThin
.Borders(xlInsideVertical).LineStyle = xlContinuous
.Borders(xlInsideVertical).Weight = xlThin
.Borders(xlInsideHorizontal).LineStyle = xlContinuous
.Borders(xlInsideHorizontal).Weight = xlThin
End With
With a.Range("B2:K" & uf)
.Borders(xlEdgeLeft).LineStyle = xlContinuous
.Borders(xlEdgeLeft).Weight = xlMedium
.Borders(xlEdgeTop).LineStyle = xlContinuous
.Borders(xlEdgeTop).Weight = xlMedium
.Borders(xlEdgeBottom).LineStyle = xlContinuous
.Borders(xlEdgeBottom).Weight = xlMedium
.Borders(xlEdgeRight).LineStyle = xlContinuous
.Borders(xlEdgeRight).Weight = xlMedium
End With
With a.Range("B" & uf + 3 & ":C" & uf + 3)
.Borders(xlEdgeLeft).LineStyle = xlContinuous
.Borders(xlEdgeLeft).Weight = xlMedium
.Borders(xlEdgeTop).LineStyle = xlContinuous
.Borders(xlEdgeTop).Weight = xlMedium
.Borders(xlEdgeBottom).LineStyle = xlContinuous
.Borders(xlEdgeBottom).Weight = xlMedium
.Borders(xlEdgeRight).LineStyle = xlContinuous
.Borders(xlEdgeRight).Weight = xlMedium
End With
With a.Range("B1:K1")
.Merge
.VerticalAlignment = xlCenter
.HorizontalAlignment = xlCenter
.RowHeight = 75
.Font.Size = 16
.Font.Bold = True
.Borders(xlEdgeLeft).LineStyle = xlContinuous
.Borders(xlEdgeLeft).Weight = xlMedium
.Borders(xlEdgeTop).LineStyle = xlContinuous
.Borders(xlEdgeTop).Weight = xlMedium
.Borders(xlEdgeBottom).LineStyle = xlContinuous
.Borders(xlEdgeBottom).Weight = xlMedium
.Borders(xlEdgeRight).LineStyle = xlContinuous
.Borders(xlEdgeRight).Weight = xlMedium
End With
 'Inserta una foto
path1 = ActiveWorkbook.Path & "\logo.jpg"
Set ran = a.Cells(1, 2)
Set imag = a.Pictures.Insert(path1)
With imag
    .Top = 0
    .Left = 100
End With
Unload Me
'Graficar
    Dim xData As Range
    Dim YData1 As Range
    Dim yData As Range
    Dim serName As Range
    'establecer los rangos para obtener los datos y la etiqueta de valor y
    Set xData = Range("C4", Range("C4").End(xlDown))
    Set yData = Range("D4", Range("D4").End(xlDown))
    Set serName = Range("B1")
    'obtener referencia a hoja activa
    Dim sht As Worksheet
    Set sht = ActiveSheet
    'crea un nuevo Objecto en la posición (28, 195) con ancho 450 y altura 250
    Dim chtObj As ChartObject
    Range("B1000").End(xlUp).Offset(3, 1).activate
    Set chtObj = ActiveSheet.ChartObjects.Add(Left:=ActiveCell.Left, Width:=810, Top:=ActiveCell.Top, Height:=300)
    'obtener referencia al objeto gráfico
    Dim cht As Chart
    Set cht = chtObj.Chart
    ' crear la nueva serie
    Dim ser As Series
    Set ser = cht.SeriesCollection.NewSeries
    ser.Values = yData
    ser.XValues = xData
    ser.Name = Range("D2")
    ser.ChartType = xlLine
    cht.Axes(xlValue).MinimumScale = Worksheets("Datos").Range("EH13")
    cht.Axes(xlValue).MaximumScale = Worksheets("Datos").Range("EH14")
    cht.Axes(xlValue).TickLabels.NumberFormat = "0,00000"
cht.SeriesCollection.NewSeries.Select
With selection
    .Name = Range("F2").Value
    .XValues = Range("C4", Range("C4").End(xlDown))
    .Values = Range("F4:F" & Range("F" & Rows.Count).End(xlUp).Row)
    cht.SeriesCollection(2).AxisGroup = xlPrimary
    cht.SeriesCollection(2).ChartType = xlLine
    cht.SeriesCollection(2).Format.Line.DashStyle = msoLineDashDot
    cht.SeriesCollection(2).Format.Line.ForeColor.RGB = &H8000&
End With
cht.SeriesCollection.NewSeries.Select
With selection
    .Name = Range("G2").Value
    .XValues = Range("C4", Range("C4").End(xlDown))
    .Values = Range("G4:G" & Range("G" & Rows.Count).End(xlUp).Row)
    cht.SeriesCollection(3).AxisGroup = xlPrimary
    cht.SeriesCollection(3).ChartType = xlLine
    cht.SeriesCollection(3).Format.Line.DashStyle = msoLineDashDot
    cht.SeriesCollection(3).Format.Line.ForeColor.RGB = &H8000&
End With
cht.SeriesCollection.NewSeries.Select
With selection
    .Name = Range("H2").Value
    .XValues = Range("C4", Range("C4").End(xlDown))
     .Values = Range("H4:H" & Range("H" & Rows.Count).End(xlUp).Row)
    cht.SeriesCollection(4).AxisGroup = xlPrimary
    cht.SeriesCollection(4).ChartType = xlLine
    cht.SeriesCollection(4).Format.Line.DashStyle = msoLineDashDot
    cht.SeriesCollection(4).Format.Line.ForeColor.RGB = &HFFFF&
End With
cht.SeriesCollection.NewSeries.Select
With selection
    .Name = Range("I2").Value
    .XValues = Range("C4", Range("C4").End(xlDown))
    .Values = Range("I4:I" & Range("I" & Rows.Count).End(xlUp).Row)
    cht.SeriesCollection(5).AxisGroup = xlPrimary
    cht.SeriesCollection(5).ChartType = xlLine
    cht.SeriesCollection(5).Format.Line.DashStyle = msoLineDashDot
    cht.SeriesCollection(5).Format.Line.ForeColor.RGB = &HFFFF&
End With
cht.SeriesCollection.NewSeries.Select
With selection
    .Name = Range("J2").Value
    .XValues = Range("C4", Range("C4").End(xlDown))
    .Values = Range("J4:J" & Range("J" & Rows.Count).End(xlUp).Row)
    cht.SeriesCollection(6).AxisGroup = xlPrimary
    cht.SeriesCollection(6).ChartType = xlLine
    cht.SeriesCollection(6).Format.Line.DashStyle = msoLineDashDot
    cht.SeriesCollection(6).Format.Line.ForeColor.RGB = &HFF&
End With
cht.SeriesCollection.NewSeries.Select
With selection
    .Name = Range("K2").Value
    .XValues = Range("C4", Range("C4").End(xlDown))
    .Values = Range("K4:K" & Range("K" & Rows.Count).End(xlUp).Row)
    cht.SeriesCollection(7).AxisGroup = xlPrimary
    cht.SeriesCollection(7).ChartType = xlLine
    cht.SeriesCollection(7).Format.Line.DashStyle = msoLineDashDot
    cht.SeriesCollection(7).Format.Line.ForeColor.RGB = &HFF&
End With
cht.SeriesCollection.NewSeries.Select
With selection
    .Name = Range("E2").Value
    .XValues = Range("C4", Range("C4").End(xlDown))
    .Values = Range("E4:E" & Range("E" & Rows.Count).End(xlUp).Row)
    cht.SeriesCollection(8).AxisGroup = xlSecondary
    cht.SeriesCollection(8).ChartType = xlColumnClustered
    cht.SeriesCollection(8).Format.Fill.ForeColor.RGB = RGB(192, 192, 192)
End With
ser.ChartType = xlLine
'*************************************************************************************************
Fila_Final = Range("D" & Cells.Rows.Count).End(xlUp).Row
Range("D4:D" & Fila_Final).NumberFormat = "0,0000"
'Cells(filaEXCEL, 1).Value = Replace(ListBoxfacturas.List(x, 0), ".", "") 'n°fact
'activate = [INDEX((Activate/2),)]
'Fila_Final = Range("F" & Cells.Rows.Count).End(xlUp).Row
'Range("F4:K" & Fila_Final).Select
'***************************************************************************************************
ActiveWorkbook.Save
'Unload Me
Application.DisplayAlerts = False
Application.ScreenUpdating = True
'Call InfReporte
End Sub

Consulta Dante como hago para enviarte archivo para que lo veas con más detalle. Gracias un abrazo.

Disculpa por responder aun cuando la pregunta no es para mi pero lo que se observa en su macro, no esta haciéndolo como se le sugirió.

Tampoco menciona en que línea de su código tiene el problema, por lo que se observa en su macro, una de las líneas de código que pongo como ejemplo que quizá es donde tenga el problema.

2 opciones que se le sugirió:
Cdbl(ListBox1. List(i, 1))
Val(ListBox1.List(i, 1))
'Adaptado a una de sus lineas de código:
ListBox1. List(ListBox1.ListCount - 1, 4) = Val(ListBox1. List(ListBox1.ListCount - 1, 4))
ListBox1. List(ListBox1.ListCount - 1, 4) = CDbl(ListBox1. List(ListBox1.ListCount - 1, 4))
Respuesta

Prueba también con lo siguiente:

Cdbl(ListBox1. List(i, 1))

Si no te funcionan las opciones, podrías poner un ejemplo de cómo tienes el dato en el listbox y cómo debería quedar en la hoja.

También pon aquí el código que estás utilizando para poner los datos en la hoja.


Para insertar código, utiliza lo siguiente:

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas