I’m attempting to assemble a ws with several columns of data.
Macro1 works just fine.
Except for the column & iRow cell references, Macro2 appears to me to be the same code. However, it replaces the existing data.
Any ideas on how can this be resolved?
Macro1 works just fine.
Except for the column & iRow cell references, Macro2 appears to me to be the same code. However, it replaces the existing data.
Any ideas on how can this be resolved?
Rich (BB code):
SubMacro1()
Dim FullName As String
Dim iRow As Long
Dim ws As Worksheet
Set ws =Worksheets("Teams")
ws.Select
ws.Unprotect
FullName = UserFormPostScores.ComboBox1
With ws
If UserFormPostScores.TextBox85.Value =1 Then
FullName =UserFormPostScores.ComboBox1.Value
Set CLoc =ws.Columns("B:B").Find(What:=FullName, after:=ws.Cells(1, 2),LookIn:= _
xlFormulas,LookAt:=xlWhole, SearchOrder:=xlByColumns, SearchDirection:= _
xlNext,MatchCase:=False, SearchFormat:=False)
If CLoc Is Nothing Then
iRow = ws.Cells(Rows.Count, 1) _
.End(xlUp).Offset(1, 0).Row
Else
iRow = CLoc.Row
End If
ws.Cells(iRow, 1).Formula ="=Rand()"
ws.Cells(iRow, 2).Value =UserFormPostScores.ComboBox1
ws.Cells(iRow, 3).Value =UserFormPostScores.TextBox90
ws.Cells(iRow, 4).Value =UserFormPostScores.TextBox36.Value
ws.Cells(iRow, 5).Value =UserFormPostScores.TextBox24.Value - UserFormPostScores.TextBox3.Value
Else
End If
End With
CallMacroBuildTeams2
End Sub
__________________________________
Sub Macro2()
Dim FullNameAs String
Dim iRow As Long
Dim ws As Worksheet
Set ws =Worksheets("Teams")
ws.Select
ws.Unprotect
FullName = UserFormPostScores.ComboBox1
With ws
If UserFormPostScores.TextBox85.Value =2 Then
FullName =UserFormPostScores.ComboBox1.Value
Set CLoc =ws.Columns("G:G").Find(What:=FullName, after:=ws.Cells(1, 7),LookIn:= _
xlFormulas, LookAt:=xlWhole,SearchOrder:=xlByColumns, SearchDirection:= _
xlNext,MatchCase:=False, SearchFormat:=False)
If CLoc Is Nothing Then
iRow = ws.Cells(Rows.Count, 1) _
.End(xlUp).Offset(1, 0).Row
Else
iRow = CLoc.Row
End If
ws.Cells(iRow, 6).Formula ="=Rand()"
ws.Cells(iRow, 7).Value =UserFormPostScores.ComboBox1
ws.Cells(iRow, 8).Value =UserFormPostScores.TextBox90
ws.Cells(iRow, 9).Value =UserFormPostScores.TextBox36.Value
ws.Cells(iRow, 10).Value =UserFormPostScores.TextBox24.Value - UserFormPostScores.TextBox3.Value
Else
End If
End With
End Sub