ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   statement invalid outside type block (https://www.excelbanter.com/excel-programming/382830-statement-invalid-outside-type-block.html)

[email protected]

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


[email protected]

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




Jim Rech

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
|
|



[email protected]

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
|
|




Dave Peterson

statement invalid outside type block
 
This worked for me:

Dim endCol As Long
Dim Result() As Long
'...
endCol = 5
ReDim Result(0 To endCol - 1)



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


--

Dave Peterson


All times are GMT +1. The time now is 11:28 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com