VBA ; Clear Content From C2 to E8 and Move up

muhammad susanto

Well-known Member
Joined
Jan 8, 2013
Messages
2,077
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
hi all..
this code not fully working, how t o fix it to delete content with data up if there is blank row (above), and in col "name" automatic delete if data move up
this code:
VBA Code:
Sub clearcontent()
    Dim lngLastRow As Long
    Dim wsSrc As Worksheet
 
    With Application
        .ScreenUpdating = False
        .EnableEvents = False
        .Calculation = xlCalculationManual
    End With
 
    Set wsSrc = ActiveSheet
    lngLastRow = wsSrc.Range("C:E").Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
 
    Dim RowsToDelete As Range
    ' Only delete the table area (If you know you have nothing to the right you could dispense
    ' with the intersect and just delete the entirerow)
    Set RowsToDelete = Intersect(wsSrc.Range("C2:E" & lngLastRow), _
                        wsSrc.Range("C2:A" & lngLastRow).SpecialCells(xlCellTypeBlanks).EntireRow)
    RowsToDelete.Delete Shift:=xlUp
 
    With Application
        .ScreenUpdating = True
        .EnableEvents = True
        .Calculation = xlCalculationAutomatic
        .CalculateFull
    End With
End Sub
this my table (before run macro):
Book1
ABCDEFG
1RefREF VerifnameNOMOR REGISTER LELANGREGISTER LELANGTahun LelangBulan Lelang
21AJohn1ok20207
32AJohn34good20207
43AJohn20207
54A1Johnexcelent20207
65A2John20207
76A3John5poor20205
87A4John4bad20205
Sheet1

expected result (after run macro)
Book1
ABCDEFG
11RefREF VerifnameNOMOR REGISTER LELANGREGISTER LELANGTahun LelangBulan Lelang
121AJohn1ok20207
132AJohn34good20207
143AJohnexcelent20207
154A1John5poor20207
165A2John4bad20207
176A320205
187A420205
Sheet1

thank in advance
susanto
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
hi Zot...i think i missing problem for like this
Book1
ABCDEFG
1NoRefnameRegcoreYearmonth
21AJohn1ok20207
32AJohn34good20207
43AJohn20207
54A1mikaexcelent20207
65A2budi20207
76A3John5poor20205
87A4John4bad20205
98B1Frans
109B3Job
1110C4Bob
1211F2Jacl5wors20206
Sheet1

after run macro
Book1
ABCDEFG
15NoRefnameRegcoreYearmonth
161AJohn1ok20207
172AJohn34good20207
183AJohn20207
194A1mikaexcelent20207
205A2budi20207
216A3John5poor20205
227A4John4bad20205
238B1Jacl5wors20206
249B3
2510C4
2611F2
Sheet1

criteria:
-in Col. C always/default contains name not allowed empty cell
- if in col D till to G is empty/blank cell, clear contains data in col C (C9 til C11) then move up data in below to fill above
please do not Delete Rows , i want just clear contains
- col A & B don't change anything
thanks before it.
 
Upvote 0
Here is the modified code
VBA Code:
Sub clearcontent()
    Dim lngLastRow As Long, n As Long
    Dim wsSrc As Worksheet
 
    With Application
        .ScreenUpdating = False
        .EnableEvents = False
        .Calculation = xlCalculationManual
    End With
 
    Set wsSrc = ActiveSheet
    lngLastRow = wsSrc.Range("C:E").Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
 
    Dim RowsToDelete As Range
    For n = 2 To lngLastRow
        If Application.WorksheetFunction.CountA(wsSrc.Range("D" & n, "G" & n)) = 0 Then
            If RowsToDelete Is Nothing Then
                Set RowsToDelete = wsSrc.Range("C" & n, "G" & n)
            Else
                Set RowsToDelete = Application.Union(RowsToDelete, wsSrc.Range("C" & n, "G" & n))
            End If
        End If
    Next
    RowsToDelete.Delete xlUp

    With Application
        .ScreenUpdating = True
        .EnableEvents = True
        .Calculation = xlCalculationAutomatic
        .CalculateFull
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,248
Messages
6,171,027
Members
452,374
Latest member
keccles

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