learning1984
New Member
- Joined
- Mar 2, 2016
- Messages
- 14
Good evening,
ive been attacking this code for ages and just cant get it to run. its not the tidiest code but it made sense to do it this way in my head. ive created a userform,which I want to transfer into 5 rows in a spreadsheet. the first few columns would all contain the same info, name, date etc, but the ones after will contain 1 of 5 fields
every rime I import a completed form, it only transfers the final if statement across into my spread sheet,
how can I amend the code so that the first if statement is honoured, and then it moves onto the next if statement.
as a side note, I am also adding a section of code that will force the user to fill in all 5 of these different fields, so every time I import the form, it should always create 5 rows of information.
my code is here:
Private Sub CommandButton1_Click()
Application.ScreenUpdating = False
Dim nextrow As Long
'Make Log active
log.Activate
If areadam01 <> "" Then
'Determine nextrow
nextrow = WorksheetFunction.CountA(Range("a:a")) + 1
Cells(nextrow, 2).Value = TextBox7.Value
Cells(nextrow, 3).Value = CDate(TextBox78.Value)
Cells(nextrow, 4).Value = ComboBox16.Value
Cells(nextrow, 5).Value = ComboBox15.Value
Cells(nextrow, 6).Value = ComboBox9.Value
Cells(nextrow, 7).Value = ComboBox8.Value
Cells(nextrow, 8).Value = TextBox9.Value
Cells(nextrow, 9).Value = ComboBox10.Value
Cells(nextrow, 10).Value = ComboBox1.Value
Cells(nextrow, 11).Value = Floc01.Text
Cells(nextrow, 12).Value = Equip01.Text
Cells(nextrow, 13).Value = Ref01.Text
Cells(nextrow, 14).Value = areadam01.Value
Cells(nextrow, 15).Value = areatime01.Value
Cells(nextrow, 16).Value = areadesc01.Value
End If
If areadam02 <> "" Then
nextrow = WorksheetFunction.CountA(Range("a:a")) + 1
Cells(nextrow, 2).Value = TextBox7.Value
Cells(nextrow, 3).Value = CDate(TextBox78.Value)
Cells(nextrow, 4).Value = ComboBox16.Value
Cells(nextrow, 5).Value = ComboBox15.Value
Cells(nextrow, 6).Value = ComboBox9.Value
Cells(nextrow, 7).Value = ComboBox8.Value
Cells(nextrow, 8).Value = TextBox9.Value
Cells(nextrow, 9).Value = ComboBox10.Value
Cells(nextrow, 10).Value = ComboBox1.Value
Cells(nextrow, 11).Value = Floc02.Value
Cells(nextrow, 12).Value = Equip02.Value
Cells(nextrow, 13).Value = Ref02.Value
Cells(nextrow, 14).Value = areadam02.Value
Cells(nextrow, 15).Value = areatime02.Value
Cells(nextrow, 16).Value = areadesc02.Value
End If
If areadam03 <> "" Then
nextrow = WorksheetFunction.CountA(Range("a:a")) + 1
Cells(nextrow, 2).Value = TextBox7.Value
Cells(nextrow, 3).Value = CDate(TextBox78.Value)
Cells(nextrow, 4).Value = ComboBox16.Value
Cells(nextrow, 5).Value = ComboBox15.Value
Cells(nextrow, 6).Value = ComboBox9.Value
Cells(nextrow, 7).Value = ComboBox8.Value
Cells(nextrow, 8).Value = TextBox9.Value
Cells(nextrow, 9).Value = ComboBox10.Value
Cells(nextrow, 10).Value = ComboBox1.Value
Cells(nextrow, 11).Value = Floc03.Value
Cells(nextrow, 12).Value = Equip03.Value
Cells(nextrow, 13).Value = Ref03.Value
Cells(nextrow, 14).Value = areadam03.Value
Cells(nextrow, 15).Value = areatime03.Value
Cells(nextrow, 16).Value = areadesc03.Value
End If
If areadam04 <> "" Then
nextrow = WorksheetFunction.CountA(Range("a:a")) + 1
Cells(nextrow, 2).Value = TextBox7.Value
Cells(nextrow, 3).Value = CDate(TextBox78.Value)
Cells(nextrow, 4).Value = ComboBox16.Value
Cells(nextrow, 5).Value = ComboBox15.Value
Cells(nextrow, 6).Value = ComboBox9.Value
Cells(nextrow, 7).Value = ComboBox8.Value
Cells(nextrow, 8).Value = TextBox9.Value
Cells(nextrow, 9).Value = ComboBox10.Value
Cells(nextrow, 10).Value = ComboBox1.Value
Cells(nextrow, 11).Value = Floc04.Value
Cells(nextrow, 12).Value = Equip04.Value
Cells(nextrow, 13).Value = Ref04.Value
Cells(nextrow, 14).Value = areadam04.Value
Cells(nextrow, 15).Value = areatime04.Value
Cells(nextrow, 16).Value = areadesc04.Value
End If
If areadam05 <> "" Then
nextrow = WorksheetFunction.CountA(Range("a:a")) + 1
Cells(nextrow, 2).Value = TextBox7.Value
Cells(nextrow, 3).Value = CDate(TextBox78.Value)
Cells(nextrow, 4).Value = ComboBox16.Value
Cells(nextrow, 5).Value = ComboBox15.Value
Cells(nextrow, 6).Value = ComboBox9.Value
Cells(nextrow, 7).Value = ComboBox8.Value
Cells(nextrow, 8).Value = TextBox9.Value
Cells(nextrow, 9).Value = ComboBox10.Value
Cells(nextrow, 10).Value = ComboBox1.Value
Cells(nextrow, 11).Value = Floc05.Value
Cells(nextrow, 12).Value = Equip05.Value
Cells(nextrow, 13).Value = Ref05.Value
Cells(nextrow, 14).Value = areadam05.Value
Cells(nextrow, 15).Value = areatime05.Value
Cells(nextrow, 16).Value = areadesc05.Value
End If
Dim theRange As Range, theCell As Range, nextLong As Long
Set theRange = log.Range("a4", log.Range("a" & Rows.Count).End(xlUp))
Set theCell = log.Range("a" & Rows.Count).End(xlUp).Offset(1)
nextLong = NextNumber(theRange)
theCell.Value = nextLong
theCell.NumberFormat = """TUSC.LOSS"" 000"
Unload Me
Range("a" & Rows.Count).End(xlUp).Select
End Sub
<strike></strike>
ive been attacking this code for ages and just cant get it to run. its not the tidiest code but it made sense to do it this way in my head. ive created a userform,which I want to transfer into 5 rows in a spreadsheet. the first few columns would all contain the same info, name, date etc, but the ones after will contain 1 of 5 fields
every rime I import a completed form, it only transfers the final if statement across into my spread sheet,
how can I amend the code so that the first if statement is honoured, and then it moves onto the next if statement.
as a side note, I am also adding a section of code that will force the user to fill in all 5 of these different fields, so every time I import the form, it should always create 5 rows of information.
my code is here:
Private Sub CommandButton1_Click()
Application.ScreenUpdating = False
Dim nextrow As Long
'Make Log active
log.Activate
If areadam01 <> "" Then
'Determine nextrow
nextrow = WorksheetFunction.CountA(Range("a:a")) + 1
Cells(nextrow, 2).Value = TextBox7.Value
Cells(nextrow, 3).Value = CDate(TextBox78.Value)
Cells(nextrow, 4).Value = ComboBox16.Value
Cells(nextrow, 5).Value = ComboBox15.Value
Cells(nextrow, 6).Value = ComboBox9.Value
Cells(nextrow, 7).Value = ComboBox8.Value
Cells(nextrow, 8).Value = TextBox9.Value
Cells(nextrow, 9).Value = ComboBox10.Value
Cells(nextrow, 10).Value = ComboBox1.Value
Cells(nextrow, 11).Value = Floc01.Text
Cells(nextrow, 12).Value = Equip01.Text
Cells(nextrow, 13).Value = Ref01.Text
Cells(nextrow, 14).Value = areadam01.Value
Cells(nextrow, 15).Value = areatime01.Value
Cells(nextrow, 16).Value = areadesc01.Value
End If
If areadam02 <> "" Then
nextrow = WorksheetFunction.CountA(Range("a:a")) + 1
Cells(nextrow, 2).Value = TextBox7.Value
Cells(nextrow, 3).Value = CDate(TextBox78.Value)
Cells(nextrow, 4).Value = ComboBox16.Value
Cells(nextrow, 5).Value = ComboBox15.Value
Cells(nextrow, 6).Value = ComboBox9.Value
Cells(nextrow, 7).Value = ComboBox8.Value
Cells(nextrow, 8).Value = TextBox9.Value
Cells(nextrow, 9).Value = ComboBox10.Value
Cells(nextrow, 10).Value = ComboBox1.Value
Cells(nextrow, 11).Value = Floc02.Value
Cells(nextrow, 12).Value = Equip02.Value
Cells(nextrow, 13).Value = Ref02.Value
Cells(nextrow, 14).Value = areadam02.Value
Cells(nextrow, 15).Value = areatime02.Value
Cells(nextrow, 16).Value = areadesc02.Value
End If
If areadam03 <> "" Then
nextrow = WorksheetFunction.CountA(Range("a:a")) + 1
Cells(nextrow, 2).Value = TextBox7.Value
Cells(nextrow, 3).Value = CDate(TextBox78.Value)
Cells(nextrow, 4).Value = ComboBox16.Value
Cells(nextrow, 5).Value = ComboBox15.Value
Cells(nextrow, 6).Value = ComboBox9.Value
Cells(nextrow, 7).Value = ComboBox8.Value
Cells(nextrow, 8).Value = TextBox9.Value
Cells(nextrow, 9).Value = ComboBox10.Value
Cells(nextrow, 10).Value = ComboBox1.Value
Cells(nextrow, 11).Value = Floc03.Value
Cells(nextrow, 12).Value = Equip03.Value
Cells(nextrow, 13).Value = Ref03.Value
Cells(nextrow, 14).Value = areadam03.Value
Cells(nextrow, 15).Value = areatime03.Value
Cells(nextrow, 16).Value = areadesc03.Value
End If
If areadam04 <> "" Then
nextrow = WorksheetFunction.CountA(Range("a:a")) + 1
Cells(nextrow, 2).Value = TextBox7.Value
Cells(nextrow, 3).Value = CDate(TextBox78.Value)
Cells(nextrow, 4).Value = ComboBox16.Value
Cells(nextrow, 5).Value = ComboBox15.Value
Cells(nextrow, 6).Value = ComboBox9.Value
Cells(nextrow, 7).Value = ComboBox8.Value
Cells(nextrow, 8).Value = TextBox9.Value
Cells(nextrow, 9).Value = ComboBox10.Value
Cells(nextrow, 10).Value = ComboBox1.Value
Cells(nextrow, 11).Value = Floc04.Value
Cells(nextrow, 12).Value = Equip04.Value
Cells(nextrow, 13).Value = Ref04.Value
Cells(nextrow, 14).Value = areadam04.Value
Cells(nextrow, 15).Value = areatime04.Value
Cells(nextrow, 16).Value = areadesc04.Value
End If
If areadam05 <> "" Then
nextrow = WorksheetFunction.CountA(Range("a:a")) + 1
Cells(nextrow, 2).Value = TextBox7.Value
Cells(nextrow, 3).Value = CDate(TextBox78.Value)
Cells(nextrow, 4).Value = ComboBox16.Value
Cells(nextrow, 5).Value = ComboBox15.Value
Cells(nextrow, 6).Value = ComboBox9.Value
Cells(nextrow, 7).Value = ComboBox8.Value
Cells(nextrow, 8).Value = TextBox9.Value
Cells(nextrow, 9).Value = ComboBox10.Value
Cells(nextrow, 10).Value = ComboBox1.Value
Cells(nextrow, 11).Value = Floc05.Value
Cells(nextrow, 12).Value = Equip05.Value
Cells(nextrow, 13).Value = Ref05.Value
Cells(nextrow, 14).Value = areadam05.Value
Cells(nextrow, 15).Value = areatime05.Value
Cells(nextrow, 16).Value = areadesc05.Value
End If
Dim theRange As Range, theCell As Range, nextLong As Long
Set theRange = log.Range("a4", log.Range("a" & Rows.Count).End(xlUp))
Set theCell = log.Range("a" & Rows.Count).End(xlUp).Offset(1)
nextLong = NextNumber(theRange)
theCell.Value = nextLong
theCell.NumberFormat = """TUSC.LOSS"" 000"
Unload Me
Range("a" & Rows.Count).End(xlUp).Select
End Sub
<strike></strike>