Dim a As String, j As Integer, s As Integer
For j = 1 To 5
a = InputBox("enter a name")
Range("a1").Cells(j, 1) = a
s = Len(a)
Range("b1").Cells(j, 1) = s
Next j
End Sub
Include codes to report how many names contain more than 5 characters
Also report average number of letters of the names contain no more than 5 characters.
---------------------------------------------------------------------------------------------
Private Sub CommandButton1_Click()
Dim i as integer, N as integer, S AS INTEGER
N=inputbox(“input a number”)
S=0
For i = 1 to 10
RANGE(“A1”).CELLS(i, 1) = N
RANGE(“A1”).CELLS(i, 2) = “x”
RANGE(“A1”).CELLS(i, 3) = i
RANGE(“A1”).CELLS(i, 4) = “=”
RANGE(“A1”).CELLS(i, 5) = RANGE(“A1”).CELLS(i, 1) * RANGE(“A1”).CELLS(i, 3)
If RANGE(“A1”).CELLS(i, 5)/2 = int(RANGE(“A1”).CELLS(i, 5)/2) then
RANGE(“A1”).CELLS(i, 6) = “even number”
ELSE
RANGE(“A1”).CELLS(i, 6) = “odd number”
ENDIF
S = S + RANGE(“A1”).CELLS(i, 5)
Next i
RANGE(“A1”).CELLS(11, 5)= S
END SUB