I have long questions on a sheet in the column A and in the column B are the points of the questions. I want that the Macro copies 20 questions randomly of the question bank with the points to another Sheet. I create the Macro but the problem which I have is that some questions are too long so that I get the Ad "type mismatch". The macro is working with just short questions.
Private Sub CommandButton1_Click()
Dim i, RowNum
Dim Text As String
Sheets("Sheet1").Range("A:A").ClearContents
Sheets("Sheet1").Range("B:B").ClearContents
Text = "Summe der Punkte"
For i = 1 To 20
generate:
RowNum = Application.RoundUp(Rnd() * 100, 0)
If Application.CountIf(Sheets("Sheet1").[A:A], Sheets("Sheet2").Cells(RowNum, "A")) = 0 & Application.CountIf(Sheets("Sheet1").[B:B], Sheets("Sheet2").Cells(RowNum, "B")) = 0 Then
Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Offset(1).Value = Sheets("Sheet2").Cells(RowNum, "A").Value
Sheets("Sheet1").Range("B" & Rows.Count).End(xlUp).Offset(1).Value = Sheets("Sheet2").Cells(RowNum, "B").Value
Else
GoTo generate
End If
Next i
Sheets("Sheet1").Select
Range("B23") = WorksheetFunction.Sum(Columns(2))
Range("A23") = Text
End Sub
Can you help me how I can change the code that the macro is working with long questions. One opportunity I thought about is to define names with the names manager, but I don't know how to program that in VBA.
e.g here one question of my question bank in the sheet.
What does a red dot on a measuring device / device mean?
____________________________________________________________________________
____________________________________________________________________________
____________________________________________________________________________
, here is e.g the problem, If I just make one line it is working
Any assistance most humbly and gratefully accepted
Aucun commentaire:
Enregistrer un commentaire