Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Can any one help whats wrong with it.
Code: Sub FindMin() 'variables to hold sheet name, starting and ending comparison rows and cols etc Dim sheet_name As String Dim starting_cell_row As Integer Dim starting_cell_col As Integer Dim ending_cell_row As Integer Dim starting_comparison_col As Integer Dim ending_comparison_col As Integer Dim resutling_column As Integer Dim smallest As Variant 'variables used in the loops Dim hold As Variant Dim hold_first As Variant Dim counter As Integer Dim col As Integer Dim temp As Variant 'initiating variable values sheet_name = "Results_Macro" starting_cell_row = 6 starting_cell_col = 7 ending_cell_row = 150 starting_comparison_col = 8 ending_comparions_col = 20 resutling_column = 21 smallest = ThisWorkbook.Sheets(sheet_name).Cells(starting_cel l_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,tart ing_cell_col).Value hold_first = Abs(hold - Cells(counter, starting_comparison_col).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 I am having this subscript out of range at the very first line of the code: smallest = ThisWorkbook.Sheets(sheet_name).Cells(starting_cel l_row, starting_cell_col).Value I have double checked the sheet name it is fine, it is getting the rows and col, but smallest remains empty. Someone plz help, Thanks |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
what does 'Subscript Out of range' mean?? | Excel Worksheet Functions | |||
Subscript out of range | Excel Programming | |||
Subscript out of range | Excel Programming | |||
subscript out of range | Excel Programming | |||
SubScript Out Of Range. | Excel Programming |