Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
statement invalid outside type block
Can anyone help me out with this please, I get the error "statement
invalid outside type block" Sub minNumber() Sheet = UserForm1.TextBox1.Text ' getting values from form. startRow = UserForm1.TextBox2.Text startCol = UserForm1.TextBox7.Text endCol = UserForm1.TextBox11.Text startValRow = UserForm1.TextBox12.Text startValCol = UserForm1.TextBox4.Text endValCol = UserForm1.TextBox13.Text endValRow = UserForm1.TextBox3.Text destCol = UserForm1.TextBox10.Text result(0 To endCol - 1) As Integer ************* thats the problem line, need help ********************** smallest = Cells(startValRow, startValCol).Value For counter = startRow To endRow hold = ThisWorkbook.Sheets("Sheet1").Cells(counter, startCol).Value hold_first = Abs(hold - Cells(startValRow, startValCol).Value) smallest = Cells(startValRow, startValCol).Value For row = startValRow To endValRow For col = startValCol To endValCol temp = Abs(hold - Cells(row, col).Value) If temp <= hold_first Then smallest = Cells(row, col).Value hold_first = temp End If Next col Next row mytype.result(counter - 1) = smallest Next counter For showResult = startRow To endRow Debug.Print result(showResult) ThisWorkbook.Sheets("Sheet1").Cells(showResult + 1, destCol).Value = result(showResult) Next showResult End Sub |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
statement invalid outside type block
....and if I dont declare result array up there and use it directly to
store values (down in the code), then i get "sub or function not defined" I have also tried "type", didnt work either On Feb 8, 11:28 am, wrote: Can anyone help me out with this please, I get the error "statement invalid outside type block" Sub minNumber() Sheet = UserForm1.TextBox1.Text ' getting values from form. startRow = UserForm1.TextBox2.Text startCol = UserForm1.TextBox7.Text endCol = UserForm1.TextBox11.Text startValRow = UserForm1.TextBox12.Text startValCol = UserForm1.TextBox4.Text endValCol = UserForm1.TextBox13.Text endValRow = UserForm1.TextBox3.Text destCol = UserForm1.TextBox10.Text result(0 To endCol - 1) As Integer ************* thats the problem line, need help ********************** smallest = Cells(startValRow, startValCol).Value For counter = startRow To endRow hold = ThisWorkbook.Sheets("Sheet1").Cells(counter, startCol).Value hold_first = Abs(hold - Cells(startValRow, startValCol).Value) smallest = Cells(startValRow, startValCol).Value For row = startValRow To endValRow For col = startValCol To endValCol temp = Abs(hold - Cells(row, col).Value) If temp <= hold_first Then smallest = Cells(row, col).Value hold_first = temp End If Next col Next row mytype.result(counter - 1) = smallest Next counter For showResult = startRow To endRow Debug.Print result(showResult) ThisWorkbook.Sheets("Sheet1").Cells(showResult + 1, destCol).Value = result(showResult) Next showResult End Sub |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
statement invalid outside type block
Dim result(0 To endCol - 1) As Integer
-- Jim wrote in message ups.com... | ...and if I dont declare result array up there and use it directly to | store values (down in the code), then i get "sub or function not | defined" I have also tried "type", didnt work either | | | On Feb 8, 11:28 am, wrote: | Can anyone help me out with this please, I get the error "statement | invalid outside type block" | | Sub minNumber() | | Sheet = UserForm1.TextBox1.Text ' getting values from form. | startRow = UserForm1.TextBox2.Text | startCol = UserForm1.TextBox7.Text | endCol = UserForm1.TextBox11.Text | startValRow = UserForm1.TextBox12.Text | startValCol = UserForm1.TextBox4.Text | endValCol = UserForm1.TextBox13.Text | endValRow = UserForm1.TextBox3.Text | destCol = UserForm1.TextBox10.Text | | result(0 To endCol - 1) As Integer ************* thats the problem | line, need help ********************** | smallest = Cells(startValRow, startValCol).Value | For counter = startRow To endRow | | hold = ThisWorkbook.Sheets("Sheet1").Cells(counter, | startCol).Value | hold_first = Abs(hold - Cells(startValRow, startValCol).Value) | smallest = Cells(startValRow, startValCol).Value | | For row = startValRow To endValRow | For col = startValCol To endValCol | temp = Abs(hold - Cells(row, col).Value) | | If temp <= hold_first Then | smallest = Cells(row, col).Value | hold_first = temp | End If | Next col | Next row | | mytype.result(counter - 1) = smallest | Next counter | | For showResult = startRow To endRow | Debug.Print result(showResult) | ThisWorkbook.Sheets("Sheet1").Cells(showResult + 1, | destCol).Value = result(showResult) | Next showResult | End Sub | | |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
statement invalid outside type block
Thanks Jim, but now the error is "constant expression required" and it
points at "endCol" On Feb 8, 11:41 am, "Jim Rech" wrote: Dim result(0 To endCol - 1) As Integer -- wrote in message ups.com... | ...and if I dont declare result array up there and use it directly to | store values (down in the code), then i get "sub or function not | defined" I have also tried "type", didnt work either | | | On Feb 8, 11:28 am, wrote: | Can anyone help me out with this please, I get the error "statement | invalid outside type block" | | Sub minNumber() | | Sheet = UserForm1.TextBox1.Text ' getting values from form. | startRow = UserForm1.TextBox2.Text | startCol = UserForm1.TextBox7.Text | endCol = UserForm1.TextBox11.Text | startValRow = UserForm1.TextBox12.Text | startValCol = UserForm1.TextBox4.Text | endValCol = UserForm1.TextBox13.Text | endValRow = UserForm1.TextBox3.Text | destCol = UserForm1.TextBox10.Text | | result(0 To endCol - 1) As Integer ************* thats the problem | line, need help ********************** | smallest = Cells(startValRow, startValCol).Value | For counter = startRow To endRow | | hold = ThisWorkbook.Sheets("Sheet1").Cells(counter, | startCol).Value | hold_first = Abs(hold - Cells(startValRow, startValCol).Value) | smallest = Cells(startValRow, startValCol).Value | | For row = startValRow To endValRow | For col = startValCol To endValCol | temp = Abs(hold - Cells(row, col).Value) | | If temp <= hold_first Then | smallest = Cells(row, col).Value | hold_first = temp | End If | Next col | Next row | | mytype.result(counter - 1) = smallest | Next counter | | For showResult = startRow To endRow | Debug.Print result(showResult) | ThisWorkbook.Sheets("Sheet1").Cells(showResult + 1, | destCol).Value = result(showResult) | Next showResult | End Sub | | |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
statement invalid outside type block
|
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Help with VBA Type statement | Excel Programming | |||
Old Format or Invalid Type Library | Excel Programming | |||
HELP:old format or invalid type library | Excel Programming | |||
Why does this fail with an invalid type error | Excel Programming | |||
Need help in excel with "Statement invalid outside Type block. " error | Excel Programming |