Una famiglia di software per fogli di calcolo Microsoft con strumenti per l'analisi, la creazione di grafici e la comunicazione dei dati.
Ciao Sol39,
Qui trovi il link al file: https://we.tl/t-zb5QVlgWnD
Vorrei suggerire di utilizzare la colonna E su Sheet2 come colonna di appoggio; questa colonna può anche essere nascosta se lo si desidera.
Quindi, prova qualcosa del genere:
- Fai clic dx sulla linguetta del foglio di interesse
- Seleziona l'opzione Visualizza Codice dal **** menu contestuale risultante
- Incolla il seguente codice:
'=========>>
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Rng As Range, rCell As Range
Set Rng = Intersect(Me.Columns(sColonna_Nomi), Target)
If Not Rng Is Nothing Then
For Each rCell In Rng.Cells
Intersect(rCell.EntireRow, _
Columns(sColonna_Di_Appoggio)).Value = sParola_Chiave
Next rCell
End If
End Sub
'<<=========
Nel tuo modulo standard, incolla il seguente codice:
'=========>>
Option Explicit
Public Const sColonna_Nomi As String = "C" '<<=== Modifica
Public Const sColonna_Di_Appoggio As String = "E" '<<=== Modifica
Public Const sParola_Chiave As String = "New" '<<=== Modifica
'--------->>
Public Sub mostra()
UserForm1.Show
End Sub
'--------->>
Public Function LastRow(SH As Worksheet, _
Optional Rng As Range, _
Optional minRow As Long = 1, _
Optional sPassword As String)
Dim bProtected As Boolean
With SH
If Rng Is Nothing Then
Set Rng = .Cells
End If
bProtected = .ProtectContents = True
If bProtected Then
Application.ScreenUpdating = False
.Unprotect Password:=sPassword
End If
End With
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
If LastRow < minRow Then
LastRow = minRow
End If
If bProtected Then
SH.Protect Password:=sPassword, _
UserInterfaceOnly:=True
End If
Application.ScreenUpdating = True
End Function
'<<=========
Nel modulo di codice della tua Userform, incolla il seguente codice:
'=========>>
Option Explicit
'--------->>
Private Sub ComboBox1_Change()
Dim r As Range
Set r = Worksheets("Sheet2").Range("A:A").Find(ComboBox1)
TextBox1.Text = r.Offset(, 1)
TextBox2.Text = r.Offset(, 2)
TextBox3.Text = r.Offset(, 3)
End Sub
'--------->>
Private Sub UserForm_Initialize()
Dim WB As Workbook
Dim SH As Worksheet
Dim Rng As Range
Dim arrIn As Variant, arrNew() As Variant
Dim sNomi As String
Dim i As Long, j As Long, iCtr As Long
Dim iCol As Long
Dim UB As Long, UB2 As Long
Const sFoglio As String = "Sheet2" '<<=== Modifica
Set WB = ThisWorkbook
Set SH = WB.Sheets(sFoglio)
With SH
LRow = LastRow(SH, .Columns("A:A"), 3)
Set Rng = .Range("A3:" & sColonna_Di_Appoggio & LRow)
End With
arrIn = Rng.Resize.Value
UB = UBound(arrIn)
UB2 = UBound(arrIn, 2)
For i = LBound(arrIn) To UB
If arrIn(i, UB2) = sParola_Chiave Then
iCtr = iCtr + 1
ReDim Preserve arrNew(1 To iCtr)
arrNew(iCtr) = arrIn(i, 3)
Rng.Cells(i, UB2).ClearContents
End If
Next i
ComboBox1.RowSource = Rng.Address(External:=True)
If CBool(iCtr) Then
sNomi = Join(arrNew, vbNewLine)
Call MsgBox( _
Prompt:="I seguenti nomi sono stati aggiunti:" _
& vbNewLine & vbNewLine _
& sNomi, Buttons:=vbInformation, _
Title:="REPORT")
End If
End Sub
'<<=========
Potresti scaricare il mio file di prova Sol20190629.xlsm
===
Regards,
Norman