1004 Application Defined or Ojbect Defined error

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
 
M

merjet

Your problem is that starting_cell_row & starting_cell_col are Text.
Declare them as Integer or Long or convert them to one of those.

Hth,
Merjet
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top