delete by vba

L

Legacy 450448

Guest
[FONT=&quot]vba code will be placed in a seperate file
[/FONT]
all files are located in same place
vba code will be placed in macro.xlsm
my file name is sample1.xlsx which is closed so we have to open the the file by vba, my sample1.xlsx first sheet name can be anything
[FONT=&quot]in sample1.xlsx If cells in column B are positive then delete all the data including column B data in that row except column A
[/FONT]
after the process completed
[FONT=&quot]save and close the sample1.xlsx file
so plz have a look

[/FONT]
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Code:
Sub t()
Dim fPath As String, wb As Workbook, r As Range
fPath = ThisWorkbook.Path
Set wb = Workbooks.Open(fPath & "\sample1.xlsx")
    With wb.Sheets(1)
        For Each r In .Range("B2", .Cells(Rows.Count, 2).End(xlUp))
            If r.Value > 0 Then
                .Range(r, .Cells(r.Row, Columns.Count)).ClearContents
            End If
        Next
    End With
    wb.Close True
End Sub
 
Upvote 0
Thnx JLGWhiz Sir for giving ur precious time and Great Support to this post
Have a Great Day
 
Upvote 0

Forum statistics

Threads
1,223,748
Messages
6,174,270
Members
452,553
Latest member
red83

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