Consulting

Results 1 to 4 of 4

Thread: Macro Copy & Paste: Numeric to Alphanumeric

  1. #1
    VBAX Newbie
    Joined
    Apr 2020
    Posts
    4
    Location

    Macro Copy & Paste: Numeric to Alphanumeric

    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?

    PHP Code:
    Sub CopiaEsercizio1()
        
    Dim j As LonguR As LonguR2 As Long
        Dim numero
    bln As Boolean
        numero 
    InputBox("Scrivi il numero dell'esercizio da copiare")
        
    With Sheets("Database")
            
    uR = .Cells(Rows.Count1).End(xlUp).Row
            uR2 
    Sheets("Allenamento").Cells(Rows.Count1).End(xlUp).Row 10
            
    For 5 To uR Step 10
                
    If .Cells(j1) = Val(numeroThen
                    
    If Sheets("Allenamento").Cells(11) = "" Then uR2 19
                    
    .Range("A" ":AO" 9).Copy Sheets("Allenamento").Cells(uR2"A")
                    
    Sheets("Allenamento").Cells(uR21) = 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 Truemessaggio1messaggio2)
    End Sub 

  2. #2
    VBAX Master paulked's Avatar
    Joined
    Apr 2006
    Posts
    1,007
    Location
    Hi and welcome to the forum.

    I can't test this, but try it after changing the text in red:

    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) = numero Then ' was Val(numero)                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
    Semper in excretia sumus; solum profundum variat.

  3. #3
    VBAX Newbie
    Joined
    Apr 2020
    Posts
    4
    Location
    It Works! Thank you


    Quote Originally Posted by paulked View Post
    Hi and welcome to the forum.

    I can't test this, but try it after changing the text in red:

    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) = numero Then ' was Val(numero)                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

  4. #4
    VBAX Master paulked's Avatar
    Joined
    Apr 2006
    Posts
    1,007
    Location
    You're welcome, please mark it solved (Thread Tools on the tool bar at the top of the page)
    Semper in excretia sumus; solum profundum variat.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •