Ciao Nicola,
Buongiorno a tutti, ho bisogno del vostro aiuto per poter disporre in righe continue i dati riportati in colonne al fine di utilizzare il foglio di Excel ottenuto come base dati per altre operazioni lavorative.
I dati sono disposti in Excel in questo modo:
COGNOME E NOME INDIRIZZO TELEFONO
CICCIO PICCIO V. M. D'zeglio15 casa 1111111
cellulare 222222
ufficio 3333333
fax 4445555
BIANCO VERDE V. G. MAZZINI,14 casa 1111111
cellulare 222222
ufficio 3333333
fax 4445555
è possibile con codice VBA poter trasporre i dati nel modo sottoriportato per ogni nominativo ?
COGNOME E NOME INDIRIZZO TELEFONO colonna D colonna E colonna F
CICCIO PICCIO V. M. D'zeglio15 casa 1111111 cellulare 222222 ufficio 3333333 fax 4445555
BIANCO VERDE V. G. MAZZINI,14 casa 1111111 cellulare 222222 ufficio 3333333 fax 4445555
e cosi via per tutti gli altri.
In un modulo standard, incolla il seguente codice:
'=========>>
Option Explicit
'--------->>
Public Sub Tester()
Dim WB As Workbook
Dim srcSH As Worksheet, destSH As Worksheet
Dim srcRng As Range, destRng As Range
Dim Rng As Range, rCell As Range
Dim arrIn As Variant, arrIntestazioni As Variant
Dim LRow As Long
Dim i As Long, j As Long, k As Long, iCtr As Long
Dim NumeroDiCampi As Long ****
Const NumeroDiColonne As Long = 3 '<<===== Modifica
Const sIntstazione As String = "COGNOME E NOME," _
& "INDIRIZZO," _
& "TELEFONO," _
& "TelCell," _
& "TelUfficio," _
& "Fax"
Set WB = ThisWorkbook
With WB
Set srcSH = .Sheets("Foglio1") '<<===== Modifica
Set destSH = .Sheets("Foglio2") '<<===== Modifica
End With
arrIntestazioni = Split(sIntstazione, ",")
NumeroDiCampi = UBound(arrIntestazioni) + 1
Set destRng = destSH.Range("A1")
With destRng.Resize(1, NumeroDiCampi)
.Value = arrIntestazioni
With .Font
.Size = 12
.Color = vbBlue
.Bold = True
.Underline = True
End With
End With
On Error Resume Next
With srcSH
LRow = LastRow(srcSH, .Columns("A:A"))
Set srcRng = .Range("A2:A" & LRow)
Set Rng = srcRng.SpecialCells(xlCellTypeConstants, xlTextValues)
End With
On Error GoTo 0
If Not Rng Is Nothing Then
ReDim arrIn(1 To Rng.Cells.Count, 1 To NumeroDiCampi)
For Each rCell In Rng.Cells
iCtr = iCtr + 1
With rCell
For j = 1 To NumeroDiColonne
arrIn(iCtr, j) = .Cells.Offset(0, j - 1)
Next j
For k = j To NumeroDiCampi
arrIn(iCtr, k) = _
.Cells.Offset(k - NumeroDiColonne, _
NumeroDiColonne - 1).Value
Next k
End With
Next rCell
End If
With destRng.Offset(1).Resize(UBound(arrIn, 1), NumeroDiCampi)
.Value = arrIn
.EntireColumn.AutoFit
End With
Call MsgBox(Prompt:="Tutto fatto " _
& vbNewLine & vbNewLine _
& iCtr _
& " record trasposti su foglio " _
& destSH.Name, _
Buttons:=vbInformation, _
Title:="REPORT")
End Sub
'--------->>
Public Function LastRow(SH As Worksheet, _
Optional Rng As Range)
If Rng Is Nothing Then
Set Rng = SH.Cells
End If
On Error Resume Next
LastRow = Rng.Find(What:="*", _
after:=Rng.Cells(1), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
On Error GoTo 0
End Function
'<<=========
Potresti scaricare il mio file di prova Nicola20151006.xlsm a:
**http://1drv.ms/1OVYgTq**
===
Regards,
Norman