'Type mismatch error for worksheet object in VBA, how can i solve?

'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 = "operasyon"
ws.Cells(1, 2).Value = "öncelik"
ws.Cells(1, 3).Value = "ardillik"
ws.Cells(1, 4).Value = "operasyon süresi"
ws.Cells(1, 5).Value = "sabit istasyon"
ws.Cells(1, 6).Value = "distinct_istasyon"
ws.Cells(1, 7).Value = "istasyon"

Columns(6).RemoveDuplicates Columns:=Array(1)


For b = lastrow To 1 Step -1
If Cells(b, 1).Text = "#N/A" 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'

I got mismatch error in "If ws.Cells(i, 1).Value = ws.Cells(j, 2).Value Then" line how can i solve this error? I add additional codes below them. İ try cstr function but it cant work? Could you please help with these additional codes. The error is in the same line and it use user form text box value to refer the sheet



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source