+ Reply to Thread
Results 1 to 3 of 3

need help in the code

  1. #1
    Deepak Varde
    Guest

    need help in the code

    in the below I am unable to get the for next loops to recall the inputs
    stored in a String variable.

    My below code works, but it takes the last value of the string and proceeds.
    I want it to ask the same questions for all the stored string values.
    Could you provide me the solution?

    My code :

    Dim groupamount
    Dim groupname As String
    Dim i As Long
    Dim d As Long

    ' This section Gets Group Names

    groupamount = InputBox("how many groups have you made?")
    ActiveCell.Offset(4, 2).Insert
    If groupamount <> "" Then
    For i = 1 To groupamount
    groupname = InputBox("what is the name of your group " & i)
    ActiveCell.Offset(i, 0).Value = groupname
    Next i
    d = groupamout - 1
    End If

    ' This section captures Threats
    Dim Threatnumber
    Dim increase As Long
    Dim threatname As String
    Dim decrease As Long

    Threatnumber = InputBox("How many threats do you foresee for " & groupname &
    " group?")

    If Threatnumber <> "" Then
    For increase = 1 To Threatnumber
    threatname = InputBox("what is the name of your " & increase & "
    threat?")
    ActiveCell.Offset(8, 4).Insert
    ActiveCell.Offset(increase, 4).Value = threatname
    Next increase
    End If

  2. #2
    Toppers
    Guest

    RE: need help in the code

    ...like this ...?

    Sub x()
    Dim groupamount
    Dim groupname As String
    Dim i As Long
    Dim d As Long
    ' This section captures Threats
    Dim Threatnumber
    Dim increase As Long
    Dim threatname As String
    Dim decrease As Long

    ' This section Gets Group Names

    groupamount = InputBox("how many groups have you made?")
    ActiveCell.Offset(4, 2).Insert
    If groupamount <> "" Then
    For i = 1 To groupamount
    groupname = InputBox("what is the name of your group " & i)
    ActiveCell.Offset(i, 0).Value = groupname
    Threatnumber = InputBox("How many threats do you foresee for " &
    groupname & " group?")

    If Threatnumber <> "" Then
    For increase = 1 To Threatnumber
    threatname = InputBox("what is the name of your " & increase &
    "threat?")
    ActiveCell.Offset(8, 4).Insert
    ActiveCell.Offset(increase, 4).Value = threatname
    Next increase
    End If
    Next i
    d = groupamout - 1
    End If


    HTH

    "Deepak Varde" wrote:

    > in the below I am unable to get the for next loops to recall the inputs
    > stored in a String variable.
    >
    > My below code works, but it takes the last value of the string and proceeds.
    > I want it to ask the same questions for all the stored string values.
    > Could you provide me the solution?
    >
    > My code :
    >
    > Dim groupamount
    > Dim groupname As String
    > Dim i As Long
    > Dim d As Long
    >
    > ' This section Gets Group Names
    >
    > groupamount = InputBox("how many groups have you made?")
    > ActiveCell.Offset(4, 2).Insert
    > If groupamount <> "" Then
    > For i = 1 To groupamount
    > groupname = InputBox("what is the name of your group " & i)
    > ActiveCell.Offset(i, 0).Value = groupname
    > Next i
    > d = groupamout - 1
    > End If
    >
    > ' This section captures Threats
    > Dim Threatnumber
    > Dim increase As Long
    > Dim threatname As String
    > Dim decrease As Long
    >
    > Threatnumber = InputBox("How many threats do you foresee for " & groupname &
    > " group?")
    >
    > If Threatnumber <> "" Then
    > For increase = 1 To Threatnumber
    > threatname = InputBox("what is the name of your " & increase & "
    > threat?")
    > ActiveCell.Offset(8, 4).Insert
    > ActiveCell.Offset(increase, 4).Value = threatname
    > Next increase
    > End If


  3. #3
    Deepak Varde
    Guest

    RE: need help in the code

    if I have a string variable to capture user inputs to the extent of numbers
    he has provided, I want to be able to ask as many questions as equal to the
    number he has specified.
    e.g
    If the question is how many groups you have made
    he answers 2
    then my questions are : what is the name of your first group & then
    what is the name of your 2 group?
    the inputs of these questions as stored in som cell

    both the inputs refer to a string called groupaname.

    Now if I want to ask a question what is the value of your 1st group and so on
    my code below just does it for the last variable stored.
    I want it to be able to look at earlier stored values too.




    "Toppers" wrote:

    > ..like this ...?
    >
    > Sub x()
    > Dim groupamount
    > Dim groupname As String
    > Dim i As Long
    > Dim d As Long
    > ' This section captures Threats
    > Dim Threatnumber
    > Dim increase As Long
    > Dim threatname As String
    > Dim decrease As Long
    >
    > ' This section Gets Group Names
    >
    > groupamount = InputBox("how many groups have you made?")
    > ActiveCell.Offset(4, 2).Insert
    > If groupamount <> "" Then
    > For i = 1 To groupamount
    > groupname = InputBox("what is the name of your group " & i)
    > ActiveCell.Offset(i, 0).Value = groupname
    > Threatnumber = InputBox("How many threats do you foresee for " &
    > groupname & " group?")
    >
    > If Threatnumber <> "" Then
    > For increase = 1 To Threatnumber
    > threatname = InputBox("what is the name of your " & increase &
    > "threat?")
    > ActiveCell.Offset(8, 4).Insert
    > ActiveCell.Offset(increase, 4).Value = threatname
    > Next increase
    > End If
    > Next i
    > d = groupamout - 1
    > End If
    >
    >
    > HTH
    >
    > "Deepak Varde" wrote:
    >
    > > in the below I am unable to get the for next loops to recall the inputs
    > > stored in a String variable.
    > >
    > > My below code works, but it takes the last value of the string and proceeds.
    > > I want it to ask the same questions for all the stored string values.
    > > Could you provide me the solution?
    > >
    > > My code :
    > >
    > > Dim groupamount
    > > Dim groupname As String
    > > Dim i As Long
    > > Dim d As Long
    > >
    > > ' This section Gets Group Names
    > >
    > > groupamount = InputBox("how many groups have you made?")
    > > ActiveCell.Offset(4, 2).Insert
    > > If groupamount <> "" Then
    > > For i = 1 To groupamount
    > > groupname = InputBox("what is the name of your group " & i)
    > > ActiveCell.Offset(i, 0).Value = groupname
    > > Next i
    > > d = groupamout - 1
    > > End If
    > >
    > > ' This section captures Threats
    > > Dim Threatnumber
    > > Dim increase As Long
    > > Dim threatname As String
    > > Dim decrease As Long
    > >
    > > Threatnumber = InputBox("How many threats do you foresee for " & groupname &
    > > " group?")
    > >
    > > If Threatnumber <> "" Then
    > > For increase = 1 To Threatnumber
    > > threatname = InputBox("what is the name of your " & increase & "
    > > threat?")
    > > ActiveCell.Offset(8, 4).Insert
    > > ActiveCell.Offset(increase, 4).Value = threatname
    > > Next increase
    > > End If


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1