Visualizzazione dei risultati da 1 a 6 su 6
  1. #1

    Calcola numero celle

    Ciao a tutti
    Ho preparato una cartella, con vari fogli nei quali, in ogni foglio vengono inserite delle lettere ( ogni lettera ha il suo significato). Ora mi serve sapere quante lettere ci sono per ogni Range di celle e questo conteggio deve essere fatto più volte ma nello stesso tempo e nello stesso foglio premendo un tasto, mi spiego: alla pressione di questo tasto, in una tabella deve comparire quante "A", quante "BL", quante "AJ" e così via, ci sono nel range ("f10", "ap74"); sempre con la stessa pressione e nella stessa tabella, deve comparire quante "A", quante "BL", quante "AJ" e così via, ci sono nel range ("f75", "ap121"); ed ancora comparire quante "A", quante "BL", quante "AJ" e così via, ci sono nel range ("f123", "ap195") e continua.
    Un mio amico mi ha preparato un programma in VB e mi ha detto di copiarlo ma, mi viene calcolata solo una parte del foglio:

    Private Sub CommandButton1_Click()


    Dim cell As Range
    Dim rp As Integer, p As Integer, c As Integer, cl As Integer, ri As Integer, pl As Integer
    rp = 0

    For Each cell In Range("f10", "ap74")
    If cell = "rp" Then
    rp = rp + 1
    ElseIf cell = "p" Then
    p = p + 1
    ElseIf cell = "c" Then
    c = c + 1
    ElseIf cell = "cl" Then
    cl = cl + 1
    ElseIf cell = "ri" Then
    ri = ri + 1
    ElseIf cell = "pl" Then
    pl = pl + 1
    Else
    End If
    Next

    Range("al2") = rp
    Range("am2") = p
    Range("ak2") = c
    Range("an2") = cl
    Range("ao2") = ri
    Range("ap2") = pl

    End

    Continue;

    For Each cell In Range("f70", "ap121")
    If cell = "rp" Then
    rp = rp + 1
    ElseIf cell = "p" Then
    p = p + 1
    ElseIf cell = "c" Then
    c = c + 1
    ElseIf cell = "cl" Then
    cl = cl + 1
    ElseIf cell = "ri" Then
    ri = ri + 1
    ElseIf cell = "pl" Then
    pl = pl + 1
    Else
    End If
    Next

    Range("al3") = rp
    Range("am3") = p
    Range("ak3") = c
    Range("an3") = cl
    Range("ao3") = ri
    Range("ap3") = pl
    End Sub

    Qualcuno sa darmi un aiuto?
    Grazie in anticipo.
    Allyclo

  2. #2
    Moderatore di Programmazione L'avatar di alka
    Registrato dal
    Oct 2001
    residenza
    Reggio Emilia
    Messaggi
    24,480

    Moderazione

    Come ti è già stato detto in questa occasione, prima di postare si deve leggere il Regolamento della sezione.

    Il titolo è inadeguato e ho provveduto io a correggerlo questa volta. In futuro pensaci tu.
    MARCO BREVEGLIERI
    Software and Web Developer, Teacher and Consultant

    Home | Blog | Delphi Podcast | Twitch | Altro...

  3. #3
    Il codice che ti ha passato il tuo amico dovrebbe funzionare ma calcolerà solo le lettere che sono scritte negli elseif..

    Dovresti potenziarlo un po' cercando di rilevare in automatico il contenuto delle celle..

    I cicli for i sono la soluzione
    (non ho tempo sennò te lo ottimizzerei..)

  4. #4

    Calcola numero lettere in celle Excel

    Grazie Ibernet,
    ho provato ma...non ne vengo a capo!
    Se puoi, appena hai un pò di tempo, potresti darmi un'imbeccata?
    Grazie in anticipo.
    Allyclo

  5. #5
    Moderatore di Programmazione L'avatar di alka
    Registrato dal
    Oct 2001
    residenza
    Reggio Emilia
    Messaggi
    24,480

    Moderazione

    Originariamente inviato da allyclo
    ho provato ma...non ne vengo a capo!
    Posta il codice, altrimenti non è possibile spiegarti cosa non va nelle tue prove, a meno di non scrivere il codice al posto tuo.
    MARCO BREVEGLIERI
    Software and Web Developer, Teacher and Consultant

    Home | Blog | Delphi Podcast | Twitch | Altro...

  6. #6
    Dunque...
    quanto segue è quello che ha scritto il mio amico:

    Private Sub CommandButton1_Click()


    Dim cell As Range
    Dim rp As Integer, p As Integer, c As Integer, cl As Integer, ri As Integer, pl As Integer
    rp = 0

    For Each cell In Range("f10", "ap74")
    If cell = "rp" Then
    rp = rp + 1
    ElseIf cell = "p" Then
    p = p + 1
    ElseIf cell = "c" Then
    c = c + 1
    ElseIf cell = "cl" Then
    cl = cl + 1
    ElseIf cell = "ri" Then
    ri = ri + 1
    ElseIf cell = "pl" Then
    pl = pl + 1
    Else
    End If
    Next

    Range("al2") = rp
    Range("am2") = p
    Range("ak2") = c
    Range("an2") = cl
    Range("ao2") = ri
    Range("ap2") = pl

    End sub
    ---------
    poi mi ha detto di continuare che tanto era solo una trascrizione in sequenza per cui ho continuato così:

    Private Sub CommandButton1_Click()


    Dim cell As Range
    Dim rp As Integer, p As Integer, c As Integer, cl As Integer, ri As Integer, pl As Integer
    rp = 0

    For Each cell In Range("f10", "ap74")
    If cell = "rp" Then
    rp = rp + 1
    ElseIf cell = "p" Then
    p = p + 1
    ElseIf cell = "c" Then
    c = c + 1
    ElseIf cell = "cl" Then
    cl = cl + 1
    ElseIf cell = "ri" Then
    ri = ri + 1
    ElseIf cell = "pl" Then
    pl = pl + 1
    Else
    End If
    Next

    Range("al2") = rp
    Range("am2") = p
    Range("ak2") = c
    Range("an2") = cl
    Range("ao2") = ri
    Range("ap2") = pl

    End

    Continue;

    For Each cell In Range("f70", "ap121")
    If cell = "rp" Then
    rp = rp + 1
    ElseIf cell = "p" Then
    p = p + 1
    ElseIf cell = "c" Then
    c = c + 1
    ElseIf cell = "cl" Then
    cl = cl + 1
    ElseIf cell = "ri" Then
    ri = ri + 1
    ElseIf cell = "pl" Then
    pl = pl + 1
    Else
    End If
    Next

    Range("al3") = rp
    Range("am3") = p
    Range("ak3") = c
    Range("an3") = cl
    Range("ao3") = ri
    Range("ap3") = pl
    End Sub

    in pratica ho levato la parte SUB, ho inserito CONTINUE ed ho trascritto variando i range da For Each cell In Range("f10", "ap74") a For Each cell In Range("f70", "ap121") e poi da Range("al2") = rp a Range("al3") = rp e via dicendo però, nella tabella alla seconda riga mi viene il totale e non solo la parte relativa a quella riga ( non so se mi sono spiegato).
    Dove sto sbagliando?
    Grazie
    Allyclo

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.