N
Nasir.Munir
I am having error 1004. The problem is the code works fine when I
don't use the form. However, if I try to add the user form, it breaks
at trying to figure out this:
smallest = ThisWorkbook.Sheets(sheet_name).Cells(starting_cell_row,
starting_cell_col).Value
Can anyone help?
Here is my code:
Sub findMin()
sheet_name = UserForm1.TextBox1.Value
starting_cell_row = UserForm1.TextBox2.Value
starting_cell_col = UserForm1.TextBox7.Value
ending_cell_row = UserForm1.TextBox11.Value
starting_comparison_col = UserForm1.TextBox4.Value
ending_comparions_col = UserForm1.TextBox13.Value
resutling_column = UserForm1.TextBox10.Value
'''******************Trouble line, I can see it takes sheet name and
cell dimension right.***********
smallest = ThisWorkbook.Sheets(sheet_name).Cells(starting_cell_row,
starting_cell_col).Value
'''''*************************************************************************************************************
For counter = starting_cell_row To ending_cell_row 'starting and
ending row for target col
hold = ThisWorkbook.Sheets(sheet_name).Cells(counter,
starting_cell_col).Value
hold_first = Abs(hold - Cells(counter, 8).Value)
smallest = Cells(starting_cell_row, starting_cell_col).Value
For col = starting_comparison_col To ending_comparions_col
temp = Abs(hold - Cells(counter, col).Value)
If temp <= hold_first Then
smallest = Cells(counter, col).Value
hold_first = temp
End If
Next col
ThisWorkbook.Sheets(sheet_name).Cells(counter,
resutling_column).Value = smallest
Next counter
End Sub
don't use the form. However, if I try to add the user form, it breaks
at trying to figure out this:
smallest = ThisWorkbook.Sheets(sheet_name).Cells(starting_cell_row,
starting_cell_col).Value
Can anyone help?
Here is my code:
Sub findMin()
sheet_name = UserForm1.TextBox1.Value
starting_cell_row = UserForm1.TextBox2.Value
starting_cell_col = UserForm1.TextBox7.Value
ending_cell_row = UserForm1.TextBox11.Value
starting_comparison_col = UserForm1.TextBox4.Value
ending_comparions_col = UserForm1.TextBox13.Value
resutling_column = UserForm1.TextBox10.Value
'''******************Trouble line, I can see it takes sheet name and
cell dimension right.***********
smallest = ThisWorkbook.Sheets(sheet_name).Cells(starting_cell_row,
starting_cell_col).Value
'''''*************************************************************************************************************
For counter = starting_cell_row To ending_cell_row 'starting and
ending row for target col
hold = ThisWorkbook.Sheets(sheet_name).Cells(counter,
starting_cell_col).Value
hold_first = Abs(hold - Cells(counter, 8).Value)
smallest = Cells(starting_cell_row, starting_cell_col).Value
For col = starting_comparison_col To ending_comparions_col
temp = Abs(hold - Cells(counter, col).Value)
If temp <= hold_first Then
smallest = Cells(counter, col).Value
hold_first = temp
End If
Next col
ThisWorkbook.Sheets(sheet_name).Cells(counter,
resutling_column).Value = smallest
Next counter
End Sub