Link to home
Start Free TrialLog in
Avatar of Avinash Singh
Avinash Singh

asked on

delete the last cell data of each row of multiple sheet

Nothing to do with sheet1
delete the last cell data of each row of Sheet2
delete the last cell data of each row of Sheet3
delete the last cell data of each row of Sheet4

see the Result , I want the result in same sheet not in separate sheet



I have to do all this by Vba
Kindly see the sample file
Book1.xlsm
Avatar of Shums Faruk
Shums Faruk
Flag of India image

Hi Avinash,

Try below:
Sub ClearLastCell()
Dim xWs As Worksheet
Dim LRow As Long, r As Long, LCell As Long
Dim cVal As String
Application.ScreenUpdating = False
cVal = ""
For Each xWs In ThisWorkbook.Sheets
    If xWs.Name <> "Sheet1" Then
        LRow = xWs.UsedRange.Rows.Count
        For r = 1 To LRow
            LCell = xWs.Cells(r, Columns.Count).End(xlToLeft).Column
            xWs.Cells(r, LCell).Value = cVal
        Next r
    End If
Next xWs
Application.ScreenUpdating = True
End Sub

Open in new window

AvinashSingh_ClearLastCell.xlsm
Avatar of Avinash Singh
Avinash Singh

ASKER

This code deletes the last cell data of each row of all sheets and i want to delete the last cell data of each row of sheet2,sheet3,sheet4 only
Try this

Option Explicit


Sub DeleteLastCll()
    Dim oWs As Worksheet
    Dim lRw As Long
    Dim iX As Integer

    For Each oWs In ThisWorkbook.Worksheets
        If oWs.Name <> "Sheet1" Then
            For iX = 1 To oWs.Range("A1").CurrentRegion.Rows.Count
                oWs.Cells(iX, oWs.Columns.Count).End(xlToLeft).Delete
            Next iX
        End If
    Next oWs
End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Shums Faruk
Shums Faruk
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thnx Shums Sir, Thnx Roy Cox Sir for giving ur precious time and great support to this post
Shums Sir Actually i have more sheets thats why previous code was deleteing that sheets data also  but now this code is perfect, accurate and Thnx once again for the same  Sir
You're Welcome Avinash! Glad I was able to help you.