"Else without If" error in nested set of If Then's

Anniemack

New Member
Joined
Oct 11, 2018
Messages
19
Can anyone tell me what I'm missing - can't seem to find why I'm getting a compile error "Else without If". The compiler highlights the "ElseIf" line.

  • :confused: Appreciate any help! Ann


i = 2
Do While ws_targets.Cells(i, 2) <> ""

If Not (IsError(Application.Match(Val(ws_targets.Cells(i, ncol)), ws_wf_pivot.Range("A2").CurrentRegion.Columns(1), 0))) Then

nrow4 = Application.Match(Val(ws_targets.Cells(i, ncol)), ws_wf_pivot.Range("A2").CurrentRegion.Columns(1), 0) 'nrow4 is col in pivot table where WB ID matches
ws_targets.Cells(i, ncol1) = ws_wf_pivot.Cells(nrow4, 2) 'waterfall name

If wf.CountIf(ws_targets.Range(ws_targets.Cells(1, ncol), ws_targets.Cells(i - 1, ncol)), ws_targets.Cells(i, ncol)) = 0 Then 'If the Target ID has not been encountered

ws_targets.Cells(i, ncol2) = ws_wf_pivot.Cells(nrow4, 3) '2019 Awards
ws_targets.Cells(i, ncol2 + 1) = ws_wf_pivot.Cells(nrow4, 4) '2020 Awards

If ws_targets.Cells(i, ncol4) = ws_wf_pivot.Cells(nrow4, 1) Then 'If Cognos Node is same in WF and Targets
With ws_targets.Cells(i, ncol4)
.Interior.Color = RGB(248, 248, 248)
.Font.Color = RGB(0, 0, 0)
ElseIf ws_targets.Cells(i, ncol4) = "" Then 'Cognos Node blank in Targets spreadsheet
With ws_targets.Cells(i, ncol4)
.Value = ws_wf_pivot.Cells(nrow4, 1)
.Interior.Color = grey_fill
.Font.Color = green_font
Else: 'Cognos Node different in WF and Targets (purple font)
With ws_targets.Cells(i, ncol4)
.Value = ws_wf_pivot.Cells(nrow4, 1)
.Interior.Color = grey_fill
.Font.Color = purple_font
End If 'formating Waterfall ID
End If 'first encounter of target ID
End If 'target ID exists in Pivot table

i = i + 1 ' next row in Targets worksheet
Loop
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Re-posting in source code mode in hopes it will keep the indent this time. Sorry, first time posting to this site.

i = 2
Do While ws_targets.Cells(i, 2) <> ""

If Not (IsError(Application.Match(Val(ws_targets.Cells(i, ncol)), ws_wf_pivot.Range("A2").CurrentRegion.Columns(1), 0))) Then

nrow4 = Application.Match(Val(ws_targets.Cells(i, ncol)), ws_wf_pivot.Range("A2").CurrentRegion.Columns(1), 0) 'nrow4 is col in pivot table where WB ID matches
ws_targets.Cells(i, ncol1) = ws_wf_pivot.Cells(nrow4, 2) 'waterfall name

If wf.CountIf(ws_targets.Range(ws_targets.Cells(1, ncol), ws_targets.Cells(i - 1, ncol)), ws_targets.Cells(i, ncol)) = 0 Then 'If the Target ID has not been already seen in the WF data above

ws_targets.Cells(i, ncol2) = ws_wf_pivot.Cells(nrow4, 3) '2019 Awards
ws_targets.Cells(i, ncol2 + 1) = ws_wf_pivot.Cells(nrow4, 4) '2020 Awards

If ws_targets.Cells(i, ncol4) = ws_wf_pivot.Cells(nrow4, 1) Then 'If Cognos Node is same in WF and Targets
With ws_targets.Cells(i, ncol4)
.Interior.Color = RGB(248, 248, 248)
.Font.Color = RGB(0, 0, 0)
ElseIf ws_targets.Cells(i, ncol4) = "" Then 'Cognos Node blank in Targets
With ws_targets.Cells(i, ncol4)
.Value = ws_wf_pivot.Cells(nrow4, 1)
.Interior.Color = grey_fill
.Font.Color = green_font
Else: 'Cognos Node different in WF and Targets (purple font)
With ws_targets.Cells(i, ncol4)
.Value = ws_wf_pivot.Cells(nrow4, 1)
.Interior.Color = grey_fill
.Font.Color = purple_font
End If 'formating Waterfall ID
End If 'first encounter of target ID
End If 'target ID exists in Pivot table

i = i + 1 ' next row in Targets worksheet
Loop
 
Upvote 0
You are welcome.

If you use the Code Tags (hashtag icon in editor menu) around your code, it will keep your indentations.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,327
Members
452,635
Latest member
laura12345

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