Compile error and array output

Status
Not open for further replies.

cortexnotion

Board Regular
Joined
Jan 22, 2020
Messages
150
Office Version
  1. 2013
Platform
  1. Windows
Hi there

I have a problem with "Compile error - next without for". I have tried to insert the AssetArray but I haven't been able to do it correctly.

Also, is there a one liner for the output array rather than having each column as its own line?

Cheers!


VBA Code:
Sub mytest()

Dim ArrIN As Variant, ArrOUT As Variant, TechArray As Variant, HeaderArray As Variant, AssetArray As Variant
Dim LR1 As Long, i As Long, o As Long, t As Long, m As Long

LR1 = ThisWorkbook.Sheets("raw").Range("A" & Rows.Count).End(xlUp).Row
ArrIN = ThisWorkbook.Sheets("raw").Range("A2:U" & LR1).Value

HeaderArray = ThisWorkbook.Sheets("raw").Range("A1:U1").Value
AssetArray = Array("sv", "s/v", "sluice", "wo", "w/o", "wash", "hydrant")
TechArray = Array("user1", "user2", "user3")

ReDim ArrOUT(1 To LR1, 1 To 13)
o = 1

For i = LBound(ArrIN) To UBound(ArrIN)

For m = LBound(AssetArray) To UBound(AssetArray)

If (InStr(ArrIN(i, 3), "Type1") > 0 And (InStr(ArrIN(i, 5), "sv") > 0 Or InStr(ArrIN(i, 5), "s/v") > 0 Or InStr(ArrIN(i, 5), "sluice") > 0) And _
(ArrIN(i, 7) & ArrIN(i, 8) & ArrIN(i, 10) <> "") And (ArrIN(i, 7) & ArrIN(i, 8) & ArrIN(i, 10) <> "Unknown")) Or _
(InStr(ArrIN(i, 3), "Type1") > 0 And (InStr(ArrIN(i, 5), "wo") > 0 Or InStr(ArrIN(i, 5), "w/o") > 0 Or InStr(ArrIN(i, 5), "wash") > 0 Or InStr(ArrIN(i, 5), "hydrant") > 0) And _
(ArrIN(i, 7) & ArrIN(i, 10) <> "") And (ArrIN(i, 7) & ArrIN(i, 10) <> "Unknown")) Or _
(InStr(ArrIN(i, 3), "Type1") > 0 And InStr(ArrIN(i, 5), AssetArray(m)) = 0 And ArrIN(i, 7) <> "" And ArrIN(i, 7) <> "Unknown") Then
Next m

For t = LBound(TechArray) To UBound(TechArray)
If InStr(ArrIN(i, 17), TechArray(t)) > 0 Then GoTo NR1
Next t

ArrOUT(o, 1) = ArrIN(i, 1)
ArrOUT(o, 2) = ArrIN(i, 16)
ArrOUT(o, 3) = ArrIN(i, 3)
ArrOUT(o, 4) = ArrIN(i, 4)
ArrOUT(o, 5) = ArrIN(i, 6)
ArrOUT(o, 6) = ArrIN(i, 5)
ArrOUT(o, 7) = ArrIN(i, 11)
ArrOUT(o, 8) = ArrIN(i, 7)
ArrOUT(o, 9) = ArrIN(i, 8)
ArrOUT(o, 10) = ArrIN(i, 10)
ArrOUT(o, 11) = ArrIN(i, 15)
ArrOUT(o, 12) = ArrIN(i, 17)
ArrOUT(o, 13) = ArrIN(i, 18)
o = o + 1
End If

NR1: Next I

With ThisWorkbook.Sheets("Results")
.Range("A1:M1").Value = Application.Index(HeaderArray, 1, Array(1, 16, 3, 4, 6, 5, 11, 7, 8, 10, 15, 17, 18))
.Range("A2:M2").Resize(UBound(ArrOUT)).Value = ArrOUT
End With

End Sub
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Hi @cortexnotion, You have duplicate the question here

The moderator will close one of your questions, I hope it is not this one.
___________________________________________________________

The logic of your program is not adequate.
You have an If inside the For-Next statement, but you put the End If outside the For-Next statement.
So it sends you that error message.

I really couldn't tell you where the EndIf goes because I don't understand what you want to do in case this huge condition is met and what you want to do in case it doesn't.

The structure should be like this:

VBA Code:
For m = LBound(AssetArray) To UBound(AssetArray)
  If huge_condition Then
    'Code if it meets the condition.
  Else
    'Code Does not meet the condition.
  End If
Next m

Could you explain what you need.
Give examples of what you have on the sheet and what you want as result.
Use XL2BB tool, look at my signature.
 
Upvote 0
Please do not post the same question multiple times. All clarifications, follow-ups, and bumps should be posted back to the original thread.
Per forum rules, posts of a duplicate nature will be locked or deleted (rule 12 here: Forum Rules).
 
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,214,909
Messages
6,122,189
Members
449,072
Latest member
DW Draft

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top