
Sub prova()
Dim rng As Range
Dim cel As Range
Dim LR As Long
Dim ur As Long
LR = Sheets("Foglio1").Cells(Rows.Count, 3).End(xlUp).Row
Set rng = Sheets("Foglio1").Range("C10:C" & LR)
For Each cel In rng
ur = Sheets("Foglio2").Cells(Rows.Count, 1).End(xlUp).Row
If cel.Value <> "" And cel.Value <> "Codice" Then
Sheets("Foglio2").Cells(ur + 1, 1) = cel.Value
Sheets("Foglio2").Cells(ur + 1, 2) = cel.Offset(0, 1).Value
Sheets("Foglio2").Cells(ur + 1, 3) = cel.Offset(1, 5).Value
Sheets("Foglio2").Cells(ur + 1, 4) = cel.Offset(1, 6).Value
End If
Next cel
End Sub
|
Sub prova()
Dim i As Integer
Dim uRiga As Integer
Dim rng As Range
Dim cel As Range
Dim LR As Long
Dim ur As Long
Application.ScreenUpdating = False
LR = Sheets("Foglio1").Cells(Rows.Count, 3).End(xlUp).Row
Set rng = Sheets("Foglio1").Range("C10:C" & LR)
For Each cel In rng
ur = Sheets("Foglio2").Cells(Rows.Count, 1).End(xlUp).Row
If cel.Value <> "" And cel.Value <> "Codice" Then
Sheets("Foglio2").Cells(ur + 1, 1) = cel.Value
Sheets("Foglio2").Cells(ur + 1, 2) = cel.Offset(0, 1).Value
Sheets("Foglio2").Cells(ur + 1, 3) = cel.Offset(1, 5).Value
Sheets("Foglio2").Cells(ur + 1, 4) = cel.Offset(1, 6).Value
End If
Next cel
uRiga = Sheets("Foglio2").Cells(Rows.Count, 1).End(xlUp).Row
For i = uRiga To 2 Step -1
If Left(Range("a" & i).Value, 1) <> "A" Then
Range("a" & i).EntireRow.Delete
End If
Next i
Application.ScreenUpdating = True
End Sub
|
If Left(Range("a" & i).Value, 1) <> "A" |
Sub elimina_righe()
Dim Intervallo As Range
Dim Righe, R, Colonne, C, FL As Boolean
Sheets("Foglio2").Select
Set Intervallo = ActiveSheet.UsedRange
Righe = Intervallo.Rows.Count
Colonne = Intervallo.Columns.Count
For R = Righe To 1 Step -1 ' questo è il ciclo modificato
FL = False
For C = 1 To Colonne
If Intervallo(R, C) <> "" Then
FL = True
End If
Next
If FL = False Then
Intervallo(R, 1).EntireRow.Delete
End If
Next
End Sub |
Sub prova()
Dim i As Integer
Dim uRiga As Integer
Dim rng As Range
Dim cel As Range
Dim LR As Long
Dim ur As Long
Application.ScreenUpdating = False
LR = Sheets("Foglio1").Cells(Rows.Count, 3).End(xlUp).Row
Set rng = Sheets("Foglio1").Range("C10:C" & LR)
For Each cel In rng
ur = Sheets("Foglio2").Cells(Rows.Count, 1).End(xlUp).Row
If cel.Value <> "" And cel.Value <> "Codice" Then
Sheets("Foglio2").Cells(ur + 1, 1) = cel.Value
Sheets("Foglio2").Cells(ur + 1, 2) = cel.Offset(0, 1).Value
Sheets("Foglio2").Cells(ur + 1, 3) = cel.Offset(1, 5).Value
Sheets("Foglio2").Cells(ur + 1, 4) = cel.Offset(1, 6).Value
End If
Next cel
uRiga = Sheets("Foglio2").Cells(Rows.Count, 1).End(xlUp).Row
For i = uRiga To 2 Step -1
If Mid(Range("a" & i).Value, 2, 1) <> "." Then
Range("a" & i).EntireRow.Delete
End If
Next i
Application.ScreenUpdating = True
End Sub
|
Sub prova()
Dim i As Integer
Dim uRiga As Integer
Dim rng As Range
Dim cel As Range
Dim LR As Long
Dim ur As Long
Application.ScreenUpdating = False
LR = Sheets("Foglio1").Cells(Rows.Count, 3).End(xlUp).Row
Set rng = Sheets("Foglio1").Range("C10:C" & LR)
For Each cel In rng
ur = Sheets("Foglio2").Cells(Rows.Count, 1).End(xlUp).Row
If cel.Value <> "" And cel.Value <> "Codice" Then
Sheets("Foglio2").Cells(ur + 1, 1) = cel.Value
Sheets("Foglio2").Cells(ur + 1, 2) = cel.Offset(0, 1).Value
Sheets("Foglio2").Cells(ur + 1, 3) = cel.Offset(1, 5).Value
Sheets("Foglio2").Cells(ur + 1, 4) = cel.Offset(1, 6).Value
End If
Next cel
uRiga = Sheets("Foglio2").Cells(Rows.Count, 1).End(xlUp).Row
For i = uRiga To 2 Step -1
If Left(Range("a" & i).Value, 1) <> "A" Then
Range("a" & i).EntireRow.Delete
End If
Next i
Application.ScreenUpdating = True
End Sub |
Option Explicit
Sub processing()
Dim dict As Object, re As Object
Dim ac As Range, c As Range, cel As Range
Dim s As String
Dim i As Long, iRow As Long, j As Long
Dim v As Variant, o As Variant
Dim last_address As String
Dim codice As String, desc_breve As String, desc_estesa As String, u_m As String, prezzo As String
Sheets("Foglio2").Range("A2:E5000").ClearContents
Sheets("Foglio1").Select
Set dict = CreateObject("Scripting.Dictionary")
Set re = CreateObject("VBScript.RegExp")
re.Global = True
re.IgnoreCase = False 'ignore case
'Codici ammessi: A, B, C, CE, D, E, F, G, H, I, IG, IT, L, M, O, P, Q, R, SL, SIC, T.
re.Pattern = "(?:C[AE]).|(?:I[GT]).|SL.|SIC.|[ABCDEFGHILMOPQRT]."
For Each ac In Range("C:C").SpecialCells(xlCellTypeConstants)
If re.test(ac) Then
s = Trim(ac)
i = i + 1
dict.Add i, Array(s, ac.Address) 'dict(i) = contenuto cella, indirizzo cella
End If
Next
dict.Add i + 1, Array("FINE", Range(dict(i)(1)).Offset(10).Address)
iRow = 2
For j = 1 To i
Set c = Range(Range(dict(j)(1)), Range(dict(j + 1)(1)).Offset(-1, 6))
codice = dict(j)(0)
s = ""
For Each cel In c.Columns(3).Cells
If cel.MergeArea.Count = 4 And LCase(cel) <> "descrizione" Then
If Trim(cel) <> "" Then
s = s & Trim(cel) & vbCrLf
last_address = cel.Address
End If
End If
Next
desc_estesa = s
o = Split(desc_estesa, vbLf)
If Right(codice, 1) Like "[0-9]" Then
desc_breve = o(2)
Else
desc_breve = o(3)
End If
u_m = Range(last_address).Offset(1, 1)
If u_m = "" Then
u_m = Join(Application.Transpose(c.Columns(7)))
u_m = Trim(u_m)
u_m = Trim(Replace(u_m, "U.M.", ""))
End If
prezzo = Range(last_address).Offset(1, 2)
If prezzo = "" Then
prezzo = Join(Application.Transpose(c.Columns(8)))
prezzo = Trim(prezzo)
prezzo = Trim(Replace(prezzo, "PREZZO", ""))
End If
With Sheets("Foglio2")
.Cells(iRow, "A") = codice
.Cells(iRow, "B") = desc_breve
.Cells(iRow, "C") = desc_estesa
.Cells(iRow, "D") = u_m
.Cells(iRow, "E") = prezzo
End With
iRow = iRow + 1
Next
Sheets("Foglio2").Select
Cells.WrapText = False
Range("A1").Select
MsgBox "Finito!", vbInformation
End Sub
|
