VBA help

Emmily

Well-known Member
Joined
Oct 5, 2008
Messages
676
Hi, i need a vba code that will look in Col A5:A, if no data is found under neath the header "Group" then delete entire row. The desired result is shown in the second screenshot

Excel Workbook
A
5Group
6BHO
7BHO
8BHO
9BHO
10
11Group
12
13Group
14RIO
15RIO
16RIO
17
18Group
19
20Group
21
22Group
23CBA
24CBA
25CBA
26CBA
Sheet1


Excel Workbook
A
5Group
6BHO
7BHO
8BHO
9BHO
10
11Group
12RIO
13RIO
14RIO
15
16Group
17CBA
18CBA
19CBA
20CBA
21
Sheet1
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Code:
[COLOR="Navy"]Sub[/COLOR] foo()
    [COLOR="Navy"]Dim[/COLOR] i [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long[/COLOR]
    [COLOR="Navy"]Dim[/COLOR] myWs [COLOR="Navy"]As[/COLOR] Worksheet
    
    [COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] myWs [COLOR="Navy"]In[/COLOR] Sheets(Array("BHP", "RIO", "CBA"))
        [B][COLOR="Red"]With[/COLOR] [COLOR="Red"]myWs[/COLOR][/B]
            [COLOR="Navy"]For[/COLOR] i = .Cells(.Rows.Count, "A").End(xlUp).Row [COLOR="Navy"]To[/COLOR] 2 [COLOR="Navy"]Step[/COLOR] -1
                [COLOR="Navy"]If[/COLOR] .Cells(i, "A").Value = "Group" [COLOR="Navy"]And[/COLOR] LenB(.Cells(i, "A").Offset(1).Value) = 0 [COLOR="Navy"]Then[/COLOR]
                    .Cells(i, "A").Resize(2).EntireRow.Delete
                [COLOR="Navy"]End[/COLOR] [COLOR="Navy"]If[/COLOR]
            [COLOR="Navy"]Next[/COLOR] i
        [B][COLOR="Red"]End[/COLOR] [COLOR="Red"]With[/COLOR][/B]
    [COLOR="Navy"]Next[/COLOR] myWs

[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
 
Upvote 0

Forum statistics

Threads
1,224,574
Messages
6,179,628
Members
452,933
Latest member
patv

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