ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   need help in the code (https://www.excelbanter.com/excel-worksheet-functions/99626-need-help-code.html)

Deepak Varde

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

Toppers

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


Deepak Varde

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



All times are GMT +1. The time now is 01:44 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com