Private Sub UserForm_Initialize() Dim i As Long i = Sheets("Data").Range("A2").CurrentRegion.Rows.Count With ListBox1 .ColumnHeads = True .ColumnCount = 1 .RowSource = "data!" & Range("A2:B" & i).Address End With End Sub |
Sub Aggiornamento_Dati() 'Application.ScreenUpdating = False Worksheets("Creo Data Raw").Visible = True 'rende visibile il foglio Dim fileapertocheck As String Dim filedachiudere As Workbook Dim filelancio As Workbook Dim nome As String Dim MyDate, Data_vis MyDate = Date Data_vis = Date MyDate = Format(MyDate, "dd_mm_yy") nome = Application.ActiveWorkbook.Name 'Nome File Workbooks(nome).Worksheets(1).Activate Sheets(1).Range("C5:C5").ClearContents 'Pulisco campi Sheets(1).Range("C14:C14").ClearContents 'Pulisco campi ' Apre Userform1 per la scelta di paese UserForm1.Show vbModal Dim Nome_sheet, Nome_sheet1 As String Nome_sheet = "Raw DataNew " & MyDate Nome_sheet1 = "Resurces " & MyDate Application.ScreenUpdating = False |
Set rng = Sheets("Data").Range("L3").CurrentRegion
'(in un modulo qualsiasi) Option Explicit Public country As String Public code As String '--------------------------- 'Nell'userform: Private Sub CommandButton1_Click() Dim opt As Control, s As String For Each opt In Controls s = opt.Name If Left(s, 3) = "opt" And opt = True Then MsgBox opt.Caption & ": " & coll(Right(s, 1)) Exit For End If Next Sheets("Work").Activate Range("A10") = opt.Caption '<<<< si può omettere se decidi che non ti interessa il valore in una cella Range("B10") = coll(Right(s, 1)) '<<<< si può omettere se decidi che non ti interessa il valore in una cella country = opt.Caption '<<<< assegno a 'country' il nome del paese code = coll(Right(s, 1)) '<<<< assegno a 'code' la sigla del paese Unload Me End Sub |
Option Explicit Public countryDIG As String Public codeDIG As String Sub Aggiornamento_Dati() 'Application.ScreenUpdating = False Worksheets("Creo Data Raw").Visible = True 'rende visibile il foglio Dim fileapertocheck As String Dim filedachiudere As Workbook Dim filelancio As Workbook Dim nome As String Dim MyDate, Data_vis MyDate = Date Data_vis = Date MyDate = Format(MyDate, "dd_mm_yy") nome = Application.ActiveWorkbook.Name 'Nome File Workbooks(nome).Worksheets(1).Activate Sheets(1).Range("C5:C5").ClearContents 'Pulisco campi ' Apre Userform1 per la scelta di paese UserForm2.Show vbModal Dim Nome_sheet, Nome_sheet1 As String Nome_sheet = "Raw DataNew " & MyDate Nome_sheet1 = "Resurces " & MyDate Application.ScreenUpdating = False 'GoTo salta_prova 'seleziona file Wrap da copiare filedaaprire = Application.GetOpenFilename _ (Title:="Seleziona report creato WRap: 01 - Demand Enhanced ITO") ' |
Dim filedaaprire, colLetSORT, colLetteraSORT As Stringsoltanto colLetteraSORT è di tipo String, le altre sono dimensionate a Variant.
Dim filedaaprire as String, colLetSORT as String, colLetteraSORT As String.
Private Sub CommandButton1_Click() Dim opt As Control, s As String For Each opt In Controls s = opt.Name If Left(s, 3) = "opt" And opt = True Then MsgBox opt.Caption & ": " & coll(Mid(s, 4)) '<<<< edit Exit For End If Next Sheets("Work").Activate If Not (opt Is Nothing) Then Range("A10") = opt.Caption Range("B10") = coll(Mid(s, 4)) '<<<< edit End If Unload Me End Sub |
Option Explicit Private coll As Collection Private Sub Label1_Click() End Sub Private Sub UserForm_Initialize() Dim i As Long, rng As Range, cel As Range Dim s As String Dim optionBtn As Control Const NUMCOLONNE As Integer = 7 'quanti option button per ogni riga? Set rng = Sheets("Creo Data Raw").Range("L2").CurrentRegion Set rng = rng.Resize(rng.Rows.Count - 1, 1).Offset(1) Set coll = New Collection For Each cel In rng i = i + 1 Set optionBtn = UserForm2.Controls.Add("Forms.OptionButton.1", "opt" & i, True) With optionBtn 'etichetta dell'option button: il nome del paese .Caption = cel 'larghezza dell'etichetta di ogni opt.butt. .Width = 70 '<<< cambia questo valore e vedi che succede (default 70) 'posizione assoluta nel form, dipende dal precedente i Mod 7 significa posizionare sette colonne di opt.butt. per ogni riga a passi 60 px .Left = Choose((i Mod NUMCOLONNE) + 1, 430, 10, 80, 150, 220, 290, 360) 'altezza di ogni opt.butt. (in funzione del font e della dimensione!) .Height = 40 '<<< cambia questo valore e vedi che succede (default 60) 'posizione relativa nel form di ogni opt.butt. (dall'alto) calcolata in funzione del numero di colonne e della altezza di ognuno in base al font .Top = 30 + Application.Floor((i - 1) / NUMCOLONNE, 1) * (optionBtn.Height - 10) 'imposta font e dimensione .Font.Name = "Calibri" .Font.Size = 10 coll.Add cel.Offset(, 1), CStr(i) 'memorizza sigla: paese, paese es IT, Italy End With Next UserForm2.Height = Controls("opt1").Height * (i NUMCOLONNE) End Sub Private Sub CommandButton1_Click() Dim opt As Control, s As String For Each opt In Controls s = opt.Name If Left(s, 3) = "opt" And opt = True Then MsgBox opt.Caption & ": " & coll(Right(s, 4)) Exit For End If Next Sheets("Creo Data Raw").Activate If Not (opt Is Nothing) Then Range("C3") = opt.Caption '<<< si può omettere se decidi che non ti interessa il valore in una cella countryDIG = opt.Caption '<<< assegno a 'country' il nome del paese codeDIG = coll(Right(s, 4)) '<<< assegno a 'code' la sigla del paese End If Unload Me End Sub |
Option Explicit Private coll As Collection Private Sub Label1_Click() End Sub Private Sub UserForm_Initialize() Dim i As Long, rng As Range, cel As Range Dim s As String Dim optionBtn As Control Const NUMCOLONNE As Integer = 7 'quanti option button per ogni riga? Set rng = Sheets("Creo Data Raw").Range("L2").CurrentRegion Set rng = rng.Resize(rng.Rows.Count - 1, 1).Offset(1) Set coll = New Collection For Each cel In rng i = i + 1 Set optionBtn = UserForm2.Controls.Add("Forms.OptionButton.1", "opt" & i, True) With optionBtn 'etichetta dell'option button: il nome del paese .Caption = cel 'larghezza dell'etichetta di ogni opt.butt. .Width = 70 '<<< cambia questo valore e vedi che succede (default 70) 'posizione assoluta nel form, dipende dal precedente i Mod 7 significa posizionare sette colonne di opt.butt. per ogni riga a passi 60 px .Left = Choose((i Mod NUMCOLONNE) + 1, 430, 10, 80, 150, 220, 290, 360) 'altezza di ogni opt.butt. (in funzione del font e della dimensione!) .Height = 40 '<<< cambia questo valore e vedi che succede (default 60) 'posizione relativa nel form di ogni opt.butt. (dall'alto) calcolata in funzione del numero di colonne e della altezza di ognuno in base al font .Top = 30 + Application.Floor((i - 1) / NUMCOLONNE, 1) * (optionBtn.Height - 10) 'imposta font e dimensione .Font.Name = "Calibri" .Font.Size = 10 coll.Add cel.Offset(, 1), CStr(i) 'memorizza sigla: paese, paese es IT, Italy End With Next UserForm2.Height = Controls("opt1").Height * (i NUMCOLONNE) End Sub Private Sub CommandButton1_Click() Dim opt As Control, s As String For Each opt In Controls s = opt.Name If Left(s, 3) = "opt" And opt = True Then MsgBox opt.Caption & ": " & coll(Mid(s, 4)) Exit For End If Next Sheets("Creo Data Raw").Activate If Not (opt Is Nothing) Then Range("C3") = opt.Caption countryDIG = opt.Caption '<<< assegno a 'country' il nome del paese codeDIG = coll(Mid(s, 4)) '<<< assegno a 'code' la sigla del paese End If Unload Me Set UserForm2 = Nothing End Sub |