Code not working

KasperC

New Member
Joined
May 11, 2023
Messages
49
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Hello,

I'm trying to delete some rows from my data-set depending on what values certain cells contains (see code below).
It works fine if the cell is 3, the macro returns the correct values - but for the rest of the cases, the rows won't delete.
(for the reccord, I don't know for certain if the rows are deleting for the case 3, and not value 133 or 148 statement)

VBA Code:
    LastRow = ws.Cells(Rows.Count, 1).End(xlUp).Row
    Dim y As Integer
        For y = 2 To LastRow
            Select Case ws.Cells(y, 2)
                Case "0", "1", "4", "8", "9", "53"
                    ws.Cells(y, 2).EntireRow.Delete Shift:=xlUp
                Case "3"
                    If ws.Cells(y, 6).Value = "133" Or ws.Cells(y, 6).Value = "148" Then
                            ws.Cells(y, 2) = "J3"
                        Else
                            If ws.Cells(y, 6).Value = "139" Or ws.Cells(y, 6).Value = "354" Then
                                    ws.Cells(y, 2) = "JC"
                                Else
                                    ws.Cells(y, 2).EntireRow.Delete Shift:=xlUp
                                End If
                        End If
            End Select
        Next y

Any suggestions?

Best Regards,
Kasper

Edit* sorry for the short title, wrote it as a temporary title but forgot to change it before posting. Cant seem to change the title after posting
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Issiue fixed - saw I was working through the rows in the wrong direction.

Fixed with "For y = LastRow To 2 Step -1"
 
Upvote 0
Solution

Forum statistics

Threads
1,223,234
Messages
6,170,891
Members
452,366
Latest member
TePunaBloke

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