Soru İki Kod Tek Buton ile Çalıştırma

Katılım
21 Temmuz 2017
Mesajlar
59
Excel Vers. ve Dili
Solidworks Office 2019
Merhaba elimde 2 adet farklı kod bulunuyor. Fakat tek Command Button ile çalıştırmak istiyorum. Fakat alt alta eklediğim zaman çalışmıyor.

Kod 1

Kod:
Sub Ekle()

Dim WS As Worksheet
Dim Addto As Range

Set WS = Sayfa1
Set Addto = WS.Range("B4000").End(xlUp).Offset(1, 0)


With WS
Addto = UserForm1.TextBox1.Value
Addto.Offset(0, 1).Value = UserForm1.TextBox2.Value
Addto.Offset(0, 3).Value = UserForm1.TextBox3.Value
Addto.Offset(0, 5).Value = UserForm1.TextBox4.Value


End With


UserForm1.TextBox1.Value = ""
UserForm1.TextBox2.Value = ""
UserForm1.TextBox3.Value = ""
UserForm1.TextBox4.Value = ""

End Sub
Kod 2

Kod:
Sub Yeni()

If Not TextBox1 = Empty Then
        For i = 1 To Worksheets.Count
            If Sheets(i).Name = UserForm1.TextBox1 & "İhalesi" Then
                MyQ = MsgBox("Bu isimde bir var, değişik bir ismi girmelisiniz !")
                TextBox1 = Empty
                TextBox1.SetFocus
                Exit Sub
            End If
        Next
        Set NewSh = Worksheets.Add
        With NewSh
            .Name = UserForm1.TextBox1
            .Range("B1") = "İhalesi"
            .Range("C1") = UserForm1.Label2
            .Range("A1") = UserForm1.TextBox1
            .Range("D1") = UserForm1.TextBox2
                      
        End With
    End If
  
    With Range("A9:D9")
    With .Borders(xlEdgeLeft)
        .LineStyle = xlContinuous
        .Weight = xlThin
    End With
    With .Borders(xlEdgeTop)
        .LineStyle = xlContinuous
        .Weight = xlThin
    End With
    With .Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .Weight = xlThin
    End With
    With .Borders(xlEdgeRight)
        .LineStyle = xlContinuous
        .Weight = xlThin
    End With
    With .Borders(xlInsideVertical)
        .LineStyle = xlContinuous
        .Weight = xlThin
    End With
    End With
  
End Sub
Denediğim Kod

Kod:
Sub Ekle()

Dim WS As Worksheet
Dim Addto As Range

Set WS = Sayfa1
Set Addto = WS.Range("B4000").End(xlUp).Offset(1, 0)


With WS
Addto = UserForm1.TextBox1.Value
Addto.Offset(0, 1).Value = UserForm1.TextBox2.Value
Addto.Offset(0, 3).Value = UserForm1.TextBox3.Value
Addto.Offset(0, 5).Value = UserForm1.TextBox4.Value

UserForm1.TextBox1.Value = ""
UserForm1.TextBox2.Value = ""
UserForm1.TextBox3.Value = ""
UserForm1.TextBox4.Value = ""

If Not TextBox1 = Empty Then
        For i = 1 To Worksheets.Count
            If Sheets(i).Name = UserForm1.TextBox1 & "İhalesi" Then
                MyQ = MsgBox("Bu isimde bir ihale var, değişik bir ihale ismi girmelisiniz !")
                TextBox1 = Empty
                TextBox1.SetFocus
                Exit Sub
            End If
        Next
        Set NewSh = Worksheets.Add
        With NewSh
            .Name = UserForm1.TextBox1
            .Range("B1") = "İhalesi"
            .Range("C1") = UserForm1.Label2
            .Range("A1") = UserForm1.TextBox1
            .Range("D1") = UserForm1.TextBox2
                      
        End With
    End If
  
    With Range("A9:D9")
    With .Borders(xlEdgeLeft)
        .LineStyle = xlContinuous
        .Weight = xlThin
    End With
    With .Borders(xlEdgeTop)
        .LineStyle = xlContinuous
        .Weight = xlThin
    End With
    With .Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .Weight = xlThin
    End With
    With .Borders(xlEdgeRight)
        .LineStyle = xlContinuous
        .Weight = xlThin
    End With
    With .Borders(xlInsideVertical)
        .LineStyle = xlContinuous
        .Weight = xlThin
    End With
    End With
End Sub
 
Üst