))) никак не сократиться?
Private Sub CommandButton1_Click() 'OK
Dim iLastRow As Long
Selection.Value = Me.TextBox9 'название
Selection.Offset(, 1).Value = CDbl(Me.TextBox32) 'закупка
Selection.Offset(, 2).Value = CDbl(Me.TextBox6) 'цена
Selection.Offset(, 3).Value = Val(Me.TextBox30) 'остаток
If Val(Me.TextBox4) > Empty Then
Selection.Offset(, 5).Value = "МРБ"
Else
Selection.Offset(, 5).Value = Me.Label12 'где
End If
If Me.Label12.Caption = "РБ" Then
If Val(Me.TextBox4) > Empty Then
With Sheets("Магазин")
Set r = .Range(.[b2], .Range("B" & .Rows.Count).End(xlUp))
End With
Set x = r.Find(What:=TextBox9.Value, LookAt:=xlWhole)
If Not x Is Nothing Then
x.Offset(, 3).Value = x.Offset(, 3).Value + Val(Me.TextBox4)
x.Offset(, 5).Value = "МРБ"
With Sheets(2)
iLastRow = .Cells(Rows.Count, 1).End(xlUp).Row + 1
.Cells(iLastRow, 1) = Me.TextBox34 'дата
.Cells(iLastRow, 2) = x.Offset(, -1) '№
.Cells(iLastRow, 3) = Me.TextBox9 'название
.Cells(iLastRow, 4) = Val(Me.TextBox4) 'приход
.Cells(iLastRow, 6) = CDbl(Me.TextBox6) 'цена
.Cells(iLastRow, 7) = Val(Me.TextBox3) 'скидка
.Cells(iLastRow, 8) = CDbl(Me.TextBox10) 'сумма
.Cells(iLastRow, 9) = Val(Me.TextBox10) - Val(Me.TextBox2) * Val(Me.TextBox32) 'прибыль=сумма(продано)-продано*закупка
.Cells(iLastRow, 10) = "из реализации" 'перемещение
.Cells(iLastRow, 11) = Val(Me.TextBox4) 'остаток
.Cells(iLastRow, 13) = "МРБ" 'где
With Sheets(8)
iLastRow = .Cells(Rows.Count, 1).End(xlUp).Row + 1
.Cells(iLastRow, 1) = Me.TextBox34 'дата
.Cells(iLastRow, 2) = Val(Me.TextBox31) '№
.Cells(iLastRow, 3) = Me.TextBox9 'название
.Cells(iLastRow, 4) = Val(Me.TextBox1) 'приход
.Cells(iLastRow, 5) = Val(Me.TextBox2) 'продано
.Cells(iLastRow, 6) = CDbl(Me.TextBox6) 'цена
.Cells(iLastRow, 7) = Val(Me.TextBox3) 'скидка
.Cells(iLastRow, 8) = CDbl(Me.TextBox10) 'сумма
.Cells(iLastRow, 9) = Val(Me.TextBox10) - Val(Me.TextBox2) * Val(Me.TextBox32) 'прибыль=сумма(продано)-продано*закупка
.Cells(iLastRow, 10) = "в магазин " & Val(Me.TextBox4) & "шт" 'перемещение
.Cells(iLastRow, 11) = Val(Me.TextBox30) 'остаток
If Val(Me.TextBox33) > 0 Then
.Cells(iLastRow, 12) = "ВОЗВРАТ " & Val(Me.TextBox33) 'возврат
Else
End If
.Cells(iLastRow, 13) = "МРБ" 'где
End With
End With
ElseIf x Is Nothing Then
With Sheets(1)
iLastRow = .Cells(Rows.Count, 1).End(xlUp).Row + 1
.Cells(iLastRow, 1).Value = Application.Max(Sheets(1).Columns(1)) + 1 '№
.Cells(iLastRow, 2).Value = Me.TextBox9 'название
.Cells(iLastRow, 3).Value = CDbl(Me.TextBox32) 'закупка
.Cells(iLastRow, 4).Value = CDbl(Me.TextBox6) 'цена
.Cells(iLastRow, 5).Value = Val(Me.TextBox4) 'остаток
.Cells(iLastRow, 7).Value = "МРБ" 'где
With Sheets(2)
iLastRow = .Cells(Rows.Count, 1).End(xlUp).Row + 1
.Cells(iLastRow, 1) = Me.TextBox34 'дата
.Cells(iLastRow, 2) = Application.Max(Sheets(1).Columns(1)) '№
.Cells(iLastRow, 3) = Me.TextBox9 'название
.Cells(iLastRow, 4) = Val(Me.TextBox4) 'приход
.Cells(iLastRow, 6) = CDbl(Me.TextBox6) 'цена
.Cells(iLastRow, 7) = Val(Me.TextBox3) 'скидка
.Cells(iLastRow, 8) = CDbl(Me.TextBox10) 'сумма
.Cells(iLastRow, 9) = Val(Me.TextBox10) - Val(Me.TextBox2) * Val(Me.TextBox32) 'прибыль=сумма(продано)-продано*закупка
.Cells(iLastRow, 10) = "из реализации" 'перемещение
.Cells(iLastRow, 11) = Val(Me.TextBox4) 'остаток
.Cells(iLastRow, 13) = "МРБ" 'где
With Sheets(8)
iLastRow = .Cells(Rows.Count, 1).End(xlUp).Row + 1
.Cells(iLastRow, 1) = Me.TextBox34 'дата
.Cells(iLastRow, 2) = Val(Me.TextBox31) '№
.Cells(iLastRow, 3) = Me.TextBox9 'название
.Cells(iLastRow, 4) = Val(Me.TextBox1) 'приход
.Cells(iLastRow, 5) = Val(Me.TextBox2) 'продано
.Cells(iLastRow, 6) = CDbl(Me.TextBox6) 'цена
.Cells(iLastRow, 7) = Val(Me.TextBox3) 'скидка
.Cells(iLastRow, 8) = CDbl(Me.TextBox10) 'сумма
.Cells(iLastRow, 9) = Val(Me.TextBox10) - Val(Me.TextBox2) * Val(Me.TextBox32) 'прибыль=сумма(продано)-продано*закупка
.Cells(iLastRow, 10) = "в магазин " & Val(Me.TextBox4) & "шт" 'перемещение
.Cells(iLastRow, 11) = Val(Me.TextBox30) 'остаток
If Val(Me.TextBox33) > 0 Then
.Cells(iLastRow, 12) = "ВОЗВРАТ " & Val(Me.TextBox33) 'возврат
Else
End If
.Cells(iLastRow, 13) = "МРБ" 'где
End With
End With
End With
End If
ElseIf Val(Me.TextBox4) = Empty Then
With Sheets(8)
iLastRow = .Cells(Rows.Count, 1).End(xlUp).Row + 1
.Cells(iLastRow, 1) = Me.TextBox34 'дата
.Cells(iLastRow, 2) = Val(Me.TextBox31) '№
.Cells(iLastRow, 3) = Me.TextBox9 'название
.Cells(iLastRow, 4) = Val(Me.TextBox1) 'приход
.Cells(iLastRow, 5) = Val(Me.TextBox2) 'продано
.Cells(iLastRow, 6) = CDbl(Me.TextBox6) 'цена
.Cells(iLastRow, 7) = Val(Me.TextBox3) 'скидка
.Cells(iLastRow, 8) = CDbl(Me.TextBox10) 'сумма
.Cells(iLastRow, 9) = Val(Me.TextBox10) - Val(Me.TextBox2) * Val(Me.TextBox32) 'прибыль=сумма(продано)-продано*закупка
.Cells(iLastRow, 10) = Val(Me.TextBox4) 'перемещение
.Cells(iLastRow, 11) = Val(Me.TextBox30) 'остаток
If Val(Me.TextBox33) > 0 Then
.Cells(iLastRow, 12) = "ВОЗВРАТ " & Val(Me.TextBox33) 'возврат
Else
End If
.Cells(iLastRow, 13) = "РБ" 'где
End With
End If
End If
If Me.Label12.Caption = "МРБ" Then
With Sheets("Магазин")
Set r = .Range(.[b2], .Range("B" & .Rows.Count).End(xlUp))
End With
Set x = r.Find(What:=TextBox9.Value, LookAt:=xlWhole)
If Not x Is Nothing Then
x.Offset(, 3).Value = x.Offset(, 3).Value + Val(Me.TextBox4)
ElseIf Me.TextBox4.Value = Empty Then
End If
If Me.TextBox4 > Empty Then
With Sheets(2)
iLastRow = .Cells(Rows.Count, 1).End(xlUp).Row + 1
.Cells(iLastRow, 1) = Me.TextBox34 'дата
.Cells(iLastRow, 2) = x.Offset(, -1) '№
.Cells(iLastRow, 3) = Me.TextBox9 'название
.Cells(iLastRow, 4) = Val(Me.TextBox4) 'приход
.Cells(iLastRow, 6) = CDbl(Me.TextBox6) 'цена
.Cells(iLastRow, 7) = Val(Me.TextBox3) 'скидка
.Cells(iLastRow, 8) = CDbl(Me.TextBox10) 'сумма
.Cells(iLastRow, 9) = Val(Me.TextBox10) - Val(Me.TextBox2) * Val(Me.TextBox32) 'прибыль
If Val(Me.TextBox4) > 0 Then
.Cells(iLastRow, 10) = "из реализации" 'перемещение
Else
.Cells(iLastRow, 10) = Val(Me.TextBox4)
End If
.Cells(iLastRow, 11) = x.Offset(, 3).Value 'остаток
.Cells(iLastRow, 13) = Me.Label12
With Sheets(8)
iLastRow = .Cells(Rows.Count, 1).End(xlUp).Row + 1
.Cells(iLastRow, 1) = Me.TextBox34 'дата
.Cells(iLastRow, 2) = Val(Me.TextBox31) '№
.Cells(iLastRow, 3) = Me.TextBox9 'название
.Cells(iLastRow, 4) = Val(Me.TextBox1) 'приход
.Cells(iLastRow, 5) = Val(Me.TextBox2) 'продано
.Cells(iLastRow, 6) = CDbl(Me.TextBox6) 'цена
.Cells(iLastRow, 7) = Val(Me.TextBox3) 'скидка
.Cells(iLastRow, 8) = CDbl(Me.TextBox10) 'сумма
.Cells(iLastRow, 9) = Val(Me.TextBox10) - Val(Me.TextBox2) * Val(Me.TextBox32) 'прибыль=сумма(продано)-продано*закупка
If Val(Me.TextBox4) > Empty Then
.Cells(iLastRow, 10) = "в магазин " & Val(Me.TextBox4) & "шт" 'перемещение
Else
.Cells(iLastRow, 10) = Val(Me.TextBox4) 'перемещение
End If
.Cells(iLastRow, 11) = Val(Me.TextBox30) 'остаток
If Val(Me.TextBox33) > Empty Then
.Cells(iLastRow, 12) = "ВОЗВРАТ " & Val(Me.TextBox33) 'возврат
End If
.Cells(iLastRow, 13) = Me.Label12 'где
End With
End With
ElseIf Me.TextBox4 = Empty Then
With Sheets(8)
iLastRow = .Cells(Rows.Count, 1).End(xlUp).Row + 1
.Cells(iLastRow, 1) = Me.TextBox34 'дата
.Cells(iLastRow, 2) = Val(Me.TextBox31) '№
.Cells(iLastRow, 3) = Me.TextBox9 'название
.Cells(iLastRow, 4) = Val(Me.TextBox1) 'приход
.Cells(iLastRow, 5) = Val(Me.TextBox2) 'продано
.Cells(iLastRow, 6) = CDbl(Me.TextBox6) 'цена
.Cells(iLastRow, 7) = Val(Me.TextBox3) 'скидка
.Cells(iLastRow, 8) = CDbl(Me.TextBox10) 'сумма
.Cells(iLastRow, 9) = Val(Me.TextBox10) - Val(Me.TextBox2) * Val(Me.TextBox32) 'прибыль=сумма(продано)-продано*закупка
If Val(Me.TextBox4) > Empty Then
.Cells(iLastRow, 10) = "в магазин " & Val(Me.TextBox4) & "шт" 'перемещение
Else
.Cells(iLastRow, 10) = Val(Me.TextBox4) 'перемещение
End If
.Cells(iLastRow, 11) = Val(Me.TextBox30) 'остаток
If Val(Me.TextBox33) > 0 Then
.Cells(iLastRow, 12) = "ВОЗВРАТ " & Val(Me.TextBox33) 'возврат
Else
End If
.Cells(iLastRow, 13) = Me.Label12 'где
End With
End If
End If
Call hidenrows.HideRows
Unload Me
End Sub