Question:
loop a msgbox in vb excel?
2008-08-16 13:18:33 UTC
using vb in excel, create a program that display a user's name n times in a message box, then in the msg box it will display as name name name....

you will ask for the name and value of n

------

i need a code for this
Three answers:
AQuestionMark
2008-08-16 14:58:57 UTC
Alt+F11, to go to vb editor, right click on the left side icon, then insert a module to the workbook, click the module, and on the right blank area add the code below

Sub displayName()

   On Error Resume Next

   uname = InputBox("Please enter user name", "Give me a name")

   ntime = InputBox("Number of times to repeat the name", "Give me a number")

   For a = 1 To Int(ntime)

      myline = myline & uname & " "

   Next

   MsgBox myline, vbOKOnly, "Display name"

End Sub

Go back to excel worksheet, Alt+F8, run macro displayName, then you're done

If you need error checking on the number input, making sure its positive integer add this

rptQ:

before ntime = InputBox("Number of times to repeat the name", "Give me a number")

and the following line after

If ntime * 1 <> Int(ntime * 1) Or ntime * 1 < 1 Or WorksheetFunction.IsNumber(ntime * 1) = False Then GoTo rptQ:

Please contact for more info
?
2016-10-19 15:16:45 UTC
there is not any row '0' in Excel. hence, Excel can not parse the 1st new launch of your 'For' loop: Cells(0,3) additionally, observe that for the time of Excel VBA 'a' isn't comparable to 'A'. So, in case you opt for to take the 'case' out of your macro, you're able to do something like: If Ucase(ActiveSheet.Cells(a million, 3).fee) = "A" Then
AMTV
2008-08-16 13:36:36 UTC
'n = number of times

n = 10

dim i as integer

for i = 1 to n

Msgbox Application.Username

next i



Dim x As String

x = ""

For i = 1 To n

x = x & " " & Application.UserName

Next i

MsgBox x


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...