title: I got type mismatch erroron my VBA code and can+t fix it. ow can i solve this?
body: <pre><code>'Private Sub CommandButton1_Click()
  
  
  Dim MySheetu As String, ws As Worksheet
  MySheetu = operationplan.Value
  Set ws = Worksheets(MySheetu)
  
  Dim a As Variant
  Dim b As Long
  Dim c As Variant
  Dim d As Variant
  Dim e As Variant
  Dim str1 As String
  Dim str2 As String
  Dim lastrow As Long
  Dim lastcol As Long
  Dim lastrow2 As Long
  Dim lastrow3 As Long
  Dim i As Variant
  Dim j As Variant
  Dim k As Variant
  
  
  Dim dsheet As Worksheet
  lastrow = Worksheets(1).Cells(Rows.Count, 21).End(xlUp).Row
  
  For a = 2 To lastrow
  ws.Cells((a), 1).Value = Worksheets(1).Cells(a, 21).Value
  ws.Cells((a), 2).Value = Worksheets(1).Cells(a, 22).Value
  ws.Cells((a), 3).Value = Worksheets(1).Cells(a, 23).Value
  ws.Cells((a), 4).Value = Worksheets(1).Cells(a, 20).Value
  ws.Cells((a), 5).Value = Worksheets(1).Cells(a, 26).Value
  ws.Cells((a), 6).Value = Worksheets(1).Cells(a, 1).Value
  ws.Cells((a), 7).Value = Worksheets(1).Cells(a, 1).Value
  Next a
  ws.Cells(1, 1).Value = &quot;operasyon&quot;
  ws.Cells(1, 2).Value = &quot;öncelik&quot;
  ws.Cells(1, 3).Value = &quot;ardillik&quot;
  ws.Cells(1, 4).Value = &quot;operasyon süresi&quot;
  ws.Cells(1, 5).Value = &quot;sabit istasyon&quot;
  ws.Cells(1, 6).Value = &quot;distinct_istasyon&quot;
  ws.Cells(1, 7).Value = &quot;istasyon&quot;
  
  Columns(6).RemoveDuplicates Columns:=Array(1)
  
  
  For b = lastrow To 1 Step -1
  If Cells(b, 1).Text = &quot;#N/A&quot; Then
  Rows(b).Delete
  End If
  Next b
  lastrow2 = ws.Cells(Rows.Count, 1).End(xlUp).Row
  
  
  
  For i = 2 To lastrow2
      For j = 2 To lastrow2
          If ws.Cells(i, 1).Value = ws.Cells(j, 2).Value Then
              ws.Cells((j), 2) = i - 1
          End If
      Next j
  Next i'
  </code></pre>
  <p>I got type mismatch error in the last fifth row that is &quot;If ws.Cells(i, 1).Value = ws.Cells(j, 2).Value Then&quot; How can I solve this.It is try to refer worksheet by using user form txt box value. In debugging it can be seen that I can get text box value but worksheet give type mismatch error.</p>