› Sviluppare funzionalita su Microsoft Office con VBA › 1 riga tabella
Stai vedendo 3 articoli - dal 1 a 3 (di 3 totali)
-
AutoreArticoli
-
Buongiorno, come da precedente discussione sto provando a popolare una tabella, il codice funziona ma se cancello tutti i dati della tabella e provo a popolare mi dice errore runtime 91 variabile oggetto o variabile del blocco with non impostata...
Allego la parte di codice in questione.
Grazie a tutti
Private Sub Ordina_ElencoOrdini() Dim lo As ListObject Set lo = ThisWorkbook.Worksheets("Elenco Ordini").ListObjects("Tabella2") lo.Sort.SortFields.Clear lo.Sort.SortFields.Add _ Key:=lo.ListColumns(8).Range, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal lo.Sort.SortFields.Add _ Key:=lo.ListColumns(7).Range, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal lo.Sort.SortFields.Add _ Key:=lo.ListColumns(1).Range, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal With lo.Sort .Header = xlYes .MatchCase = False .Apply End With Worksheets("Elenco Ordini").Activate lo.DataBodyRange.Cells(1, 1).Select Set lo = Nothing End SubLa riga che si evidenzia nel debug è
lo.DataBodyRange.Cells(1, 1).Select
Ciao, prova a sostituite la Sub EsportaDati() con questa nuova:
Private Sub EsportaDati() Dim wsMR As Worksheet Dim arr As Variant Dim i As Byte Dim lo As ListObject Dim primaRigaVuota As Long Dim rng As Range Dim tabellaVuota As Boolean Application.ScreenUpdating = False Set wsMR = ThisWorkbook.Worksheets("MASCHERA RICERCA") Set lo = ThisWorkbook.Worksheets("Elenco Ordini").ListObjects(1) If lo.DataBodyRange Is Nothing Then primaRigaVuota = lo.HeaderRowRange.Row + 1 Else tabellaVuota = Application.WorksheetFunction.CountA(lo.DataBodyRange) = 0 If tabellaVuota Then primaRigaVuota = lo.HeaderRowRange.Row + 1 Else Set rng = lo.ListColumns(1).DataBodyRange.Find(What:="", LookIn:=xlValues) If Not rng Is Nothing Then primaRigaVuota = rng.Row Else primaRigaVuota = lo.DataBodyRange.Rows(lo.ListRows.Count).Row + 1 End If End If End If arr = Array("D2", "E2", "G11", "K26", "K35", "K6", "K8", "M37") With Sheets("Elenco Ordini") For i = LBound(arr) To UBound(arr) If IsDate(wsMR.Range(arr(i)).Value) Then .Cells(primaRigaVuota, i + 1).Value = CDate(wsMR.Range(arr(i))) .Cells(primaRigaVuota, i + 1).NumberFormat = "dd/mm/yyyy" Else .Cells(primaRigaVuota, i + 1).Value = wsMR.Range(arr(i)).Value End If Next i .Range("A" & primaRigaVuota & ":" & "H" & primaRigaVuota).Borders.LineStyle = xlContinuous With Columns("A:H") .Font.Name = "Calibri" .Font.Size = 10 .HorizontalAlignment = xlCenter .VerticalAlignment = xlCenter End With End With Application.ScreenUpdating = True Set wsMR = Nothing Set lo = Nothing Set rng = Nothing End Sub -
AutoreArticoli
Stai vedendo 3 articoli - dal 1 a 3 (di 3 totali)
