End with without with

Melrose0507

New Member
Joined
Jul 19, 2011
Messages
22
I am having issues with how to end my macro. I want to cut the cell in column H if it equals "TXT" and then insert it 5 rows to the right. Below is my macro. The error I receive is "End With without With". :confused: Some one please help guide me!!!

Private Sub TXT()
Dim LR As Long, i As Long
LR = Range("H" & Rows.Count).End(xlUp).Row
For i = LR To 2 Step -1
With Range("H" & i)
If Cells(i, "H").Value = "TXT" Then
Selection.Cut
ActiveCells.Offset(0, 5).Insert
End With
Next i
End Sub
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
This error is usually misleading...
You're actually missing an End If

Indentation of code should help uncover these types of errors.
Always indent after : IF / With / For / Do statements (among others)..

You have this
Rich (BB code):
Private Sub TXT()
Dim LR As Long, i As Long
LR = Range("H" & Rows.Count).End(xlUp).Row
For i = LR To 2 Step -1
    With Range("H" & i)
        If Cells(i, "H").Value = "TXT" Then
            Selection.Cut
            ActiveCells.Offset(0, 5).Insert
    End With
Next i
End Sub


Should be like this
Rich (BB code):
Private Sub TXT()
Dim LR As Long, i As Long
LR = Range("H" & Rows.Count).End(xlUp).Row
For i = LR To 2 Step -1
    With Range("H" & i)
        If Cells(i, "H").Value = "TXT" Then
            Selection.Cut
            ActiveCells.Offset(0, 5).Insert
        End If
    End With
Next i
End Sub
 
Upvote 0
You confused VBA by starting an If..Then block but not closing it with an End If.

Indenting and 'outdenting' your code when you start and end code blocks invariably shows up this type of error.
 
Upvote 0

Forum statistics

Threads
1,224,531
Messages
6,179,379
Members
452,907
Latest member
Roland Deschain

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