An implementation of Visual Basic that is built into Microsoft products.
Macros crashed please help
Private Sub Worksheet_Change(ByVal Target As Range)
Dim cVal As String
Dim pVal As String
Dim eVal As String
Dim rN As Integer
Dim rC As Integer
Dim cRw As String
Dim cV1 As String
Dim cV2 As String
Dim uCT As Integer 'Total unit count
Dim uCL As Integer 'Load unit count
If Not Intersect(Target, Range("D3:D62")) Is Nothing Then
cVal = ActiveCell.Value
'For x = 3 To 62
rN = ActiveCell.Row
rC = ActiveCell.Column
c1 = Range("B1").Value
cV1 = Range("B" & rN).Value
cV2 = Range("B" & rN - 1).Value
uCT = Range("C1").Value
If cV1 = "" Then
rN = rN - 1
'ElseIf cV2 = "" Then
End If
cVal = Range("D" & rN).Value 'Load Type
If c1 = "" Or IsNull(c1) Then
If rN = 2 Then
Exit Sub
Else:
'rN = rN - 1
uCL = Range("C" & rN).Value 'Load Unit Count
pVal = Range("B" & rN).Value 'PO Number
cVal = Range("D" & rN).Value 'Load Type
End If
ElseIf rC = 5 Then
'rN = rN - 1
pVal = " " & Range("B" & rN).Value
cVal = Range("D" & rN).Value
uCL = Range("C" & rN).Value 'Load Unit Count
Else:
pVal = " " & Range("B" & rN).Value
uCL = Range("C" & rN).Value 'Load Unit Count
End If
eVal = ""
'If cVal = "" And pVal = " " Then
' Exit Sub
If Range("A1").Value = "C" Then
Exit Sub
ElseIf InStr(Range("B1"), Range("C" & rN)) = 1 Then
Exit Sub
' ElseIf rC = 3 And ActiveCell.Row = rN Then
' Exit Sub
ElseIf cVal = "" Then
Range("B1").Select
ActiveCell.Characters(Len(c1) + 1).Insert pVal
colr = Range("H" & rN).Value
Range("B1").Characters(colr, 9).Font.Color = vbBlack
Range("C1").Value = uCT + uCL
Cells(rN, rC).Select
ElseIf cVal = "H" Or cVal = "h" Then
Range("B1").Select
ActiveCell.Characters(Len(c1) + 1).Insert pVal
colr = Range("H" & rN).Value
Range("B1").Characters(colr, 9).Font.Color = vbRed
Range("C1").Value = uCT + uCL
Cells(rN, rC).Select
ElseIf cVal = "B" Or cVal = "b" Then
Range("B1").Select
ActiveCell.Characters(Len(c1) + 1).Insert pVal
colr = Range("H" & rN).Value
Range("B1").Characters(colr, 9).Font.FontStyle = "Bold"
Range("B1").Characters(colr, 9).Font.Color = vbBlack
Range("C1").Value = uCT + uCL
Cells(rN, rC).Select
ElseIf cVal = "HB" Or cVal = "hB" Or cVal = "hb" Or cVal = "Hb" Then
colr = Range("H" & rN).Value
Range("B1").Select
ActiveCell.Characters(Len(c1)).Insert pVal
Range("B1").Characters(colr, 9).Font.Color = vbRed
Range("B1").Characters(colr, 9).Font.FontStyle = "Bold"
Range("C1").Value = uCT + uCL
Cells(rN, rC).Select
ElseIf cVal = "M" Or cVal = "m" Then
Range("B1").Select
ActiveCell.Characters(Len(c1) + 1).Insert pVal
colr = Range("H" & rN).Value
Range("B1").Characters(colr, 9).Font.Color = vbBlue
Range("C1").Value = uCT + uCL
Cells(rN, rC).Select
ElseIf cVal = "P" Or cVal = "p" Then
Range("B1").Select
ActiveCell.Characters(Len(c1) + 1).Insert pVal
colr = Range("H" & rN).Value
Range("B1").Characters(colr, 9).Font.Color = RGB(204, 102, 255)
Range("C1").Value = uCT + uCL
Cells(rN, rC).Select
ElseIf cVal = "S" Or cVal = "s" Then
Range("B1").Select
ActiveCell.Characters(Len(c1) + 1).Insert pVal
colr = Range("H" & rN).Value
Range("B1").Characters(colr, 9).Font.Color = vbBlack
Range("C1").Value = uCT + uCL
Cells(rN, rC).Select
End If
cV1 = Range("B" & rN).Value
If cV1 <> "" Then
'rN = rN + 1
rC = 2
Cells(rN, rC).Select
End If
'Range("D" & rN).Select
'set formula here
'Next x
'If ActiveCell.Row <> rN Then Range("B" & rN + 1).Select
End If
'Cells(rN + 1, rC).Select
If Not Intersect(Target, Range("L3:L62")) Is Nothing Then
cVal = ActiveCell.Value
'For x = 3 To 62
rN = ActiveCell.Row
rC = ActiveCell.Column
c1 = Range("J1").Value 'PO's already listed
cV1 = Range("J" & rN).Value 'New PO to add to list
cV2 = Range("J" & rN - 1).Value 'PO Above current
uCT = Range("K1").Value
If cV1 = "" Then
rN = rN - 1
'ElseIf cV2 = "" Then
End If
cVal = Range("L" & rN).Value 'Load Type
If c1 = "" Or IsNull(c1) Then
If rN = 2 Then
Exit Sub
Else:
uCL = Range("K" & rN).Value 'Load Unit Count
pVal = Range("J" & rN).Value 'PO Number
cVal = Range("L" & rN).Value 'Load Type
End If
ElseIf rC = 13 Then
'rN = rN - 1
uCL = Range("K" & rN).Value 'Load Unit Count
pVal = " " & Range("J" & rN).Value
cVal = Range("L" & rN).Value
Else:
uCL = Range("K" & rN).Value 'Load Unit Count
pVal = " " & Range("J" & rN).Value
End If
eVal = ""
'If cVal = "" And pVal = " " Then
' Exit Sub
If Range("L1").Value = "C" Then
Exit Sub
ElseIf InStr(Range("J1"), Range("J" & rN)) = 1 Then
Exit Sub
' ElseIf rC = 3 And ActiveCell.Row = rN Then
' Exit Sub
ElseIf cVal = "" Then
Range("J1").Select
ActiveCell.Characters(Len(c1) + 1).Insert pVal
colr = Range("H" & rN).Value
Range("J1").Characters(colr, 9).Font.Color = vbBlack
Range("K1").Value = uCT + uCL
Cells(rN, rC).Select
ElseIf cVal = "H" Or cVal = "h" Then
Range("J1").Select
ActiveCell.Characters(Len(c1) + 1).Insert pVal
colr = Range("H" & rN).Value
Range("J1").Characters(colr, 9).Font.Color = vbRed
Range("K1").Value = uCT + uCL
Cells(rN, rC).Select
ElseIf cVal = "B" Or cVal = "b" Then
Range("J1").Select
ActiveCell.Characters(Len(c1) + 1).Insert pVal
colr = Range("H" & rN).Value
Range("J1").Characters(colr, 9).Font.FontStyle = "Bold"
Range("J1").Characters(colr, 9).Font.Color = vbBlack
Range("K1").Value = uCT + uCL
Cells(rN, rC).Select
ElseIf cVal = "HB" Or cVal = "hB" Or cVal = "hb" Or cVal = "Hb" Then
colr = Range("H" & rN).Value
Range("J1").Select
ActiveCell.Characters(Len(c1)).Insert pVal
Range("J1").Characters(colr, 9).Font.Color = vbRed
Range("J1").Characters(colr, 9).Font.FontStyle = "Bold"
Range("K1").Value = uCT + uCL
Cells(rN, rC).Select
ElseIf cVal = "M" Or cVal = "m" Then
Range("J1").Select
ActiveCell.Characters(Len(c1) + 1).Insert pVal
colr = Range("H" & rN).Value
Range("J1").Characters(colr, 9).Font.Color = vbBlue
Range("K1").Value = uCT + uCL
Cells(rN, rC).Select
ElseIf cVal = "P" Or cVal = "p" Then
Range("J1").Select
ActiveCell.Characters(Len(c1) + 1).Insert pVal
colr = Range("H" & rN).Value
Range("J1").Characters(colr, 9).Font.Color = RGB(204, 102, 255)
Range("K1").Value = uCT + uCL
Cells(rN, rC).Select
ElseIf cVal = "S" Or cVal = "s" Then
Range("J1").Select
ActiveCell.Characters(Len(c1) + 1).Insert pVal
colr = Range("H" & rN).Value
Range("J1").Characters(colr, 9).Font.Color = vbBlack
Range("K1").Value = uCT + uCL
Cells(rN, rC).Select
End If
cV1 = Range("J" & rN).Value
If cV1 <> "" Then
'rN = rN + 1
rC = 13
Cells(rN, rC).Select
End If
'Range("D" & rN).Select
'set formula here
'Next x
'If ActiveCell.Row <> rN Then Range("B" & rN + 1).Select
End If
End Sub
my apologies for the long code
Thanks in advance