Momo81
04-20-2020, 11:40 AM
Hi, this macro works if a number is entered (1,2,10... ect). Can you change it so that an alphanumeric code (AB2, PF3, CP10...) is entered?
Sub CopiaEsercizio1()
Dim j As Long, uR As Long, uR2 As Long
Dim numero, bln As Boolean
numero = InputBox("Scrivi il numero dell'esercizio da copiare")
With Sheets("Database")
uR = .Cells(Rows.Count, 1).End(xlUp).Row
uR2 = Sheets("Allenamento").Cells(Rows.Count, 1).End(xlUp).Row + 10
For j = 5 To uR Step 10
If .Cells(j, 1) = Val(numero) Then
If Sheets("Allenamento").Cells(1, 1) = "" Then uR2 = 19
.Range("A" & j + 0 & ":AO" & j + 9).Copy Sheets("Allenamento").Cells(uR2, "A")
Sheets("Allenamento").Cells(uR2, 1) = numero
bln = True
Exit For
End If
Next j
End With
messaggio1 = "Fatto!"
messaggio2 = "Il numero scelto non corrisponde a nessun esercizio!"
MsgBox IIf(bln = True, messaggio1, messaggio2)
End Sub
Sub CopiaEsercizio1()
Dim j As Long, uR As Long, uR2 As Long
Dim numero, bln As Boolean
numero = InputBox("Scrivi il numero dell'esercizio da copiare")
With Sheets("Database")
uR = .Cells(Rows.Count, 1).End(xlUp).Row
uR2 = Sheets("Allenamento").Cells(Rows.Count, 1).End(xlUp).Row + 10
For j = 5 To uR Step 10
If .Cells(j, 1) = Val(numero) Then
If Sheets("Allenamento").Cells(1, 1) = "" Then uR2 = 19
.Range("A" & j + 0 & ":AO" & j + 9).Copy Sheets("Allenamento").Cells(uR2, "A")
Sheets("Allenamento").Cells(uR2, 1) = numero
bln = True
Exit For
End If
Next j
End With
messaggio1 = "Fatto!"
messaggio2 = "Il numero scelto non corrisponde a nessun esercizio!"
MsgBox IIf(bln = True, messaggio1, messaggio2)
End Sub