• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

VBA to prompt a certain number of input boxes

Within a much large VBA, I have a question that asks how many transactions are being reviewed and then goes on to ask for the Transaction Number for each transaction being reviewed. I cannot get this to work correctly. Are there any glaring errors in my coding?

[pre]
Code:
Dim NumsTrans as Integer
Dim TranNumi as Integer

NumsTrans = Application.InputBox("How many transactions will be reviewed?")
If NumsTrans <> 0 Then
ThisWorkbook.Names.Add Name:="TranNumbers", RefersToR1C1:= _
"=R15C16:R15C" & NumsTrans + 15
End If

For TranNumi = 1 To NumsTrans
TranNumi = TranNumi + 0
TranNumi = Range("P15"+TranNumi).Value
Next TranNumi
[/pre]
 
If NumsTrans is 0, your For statement would normally have a problem (XL will start at 1 and increment by 1 until it reaches 0...aka, infinite loop).


However, I think the current problem is your For statement defines TranNumi as being 1 to TransNum. Once you do that, don't redefine TransNumi as something else (like in the next two statements).


Additionally, there's an error in the Range object. saying "P15" + TransNumi, where TransNumi is a number is not a legitimate statement (adding text and numbers). I think you either want to concatenate, or, do something like:

Cells(15+TransNumi,"P").Value
 
[pre]
Code:
Dim i as Integer

For i = 1 To NumsTrans
TranNum = Application.InputBox("What is the transaction number for transaction " & i & "?")
Cells("15", 15 + i).Value = TranNum
Next i
[/pre]

So here are some edits I made to the second part that seem to have fixed the issue. Just thought I would share.


Thanks for the guidance Luke M.
 
Back
Top