2 Attachment(s)
If column C has blank cell then delete that entire row
If column C has blank cell then delete that entire row
Hi Experts,
I am looking for a macro that will do the things mentioed below
There are two different files(file name book1.xlsx & book2.xlsx)
If column C has a blank cell then delete that entire row by vba in both the file(check in both the file one by one & if they have a blank cell in column C then delete that entire row by vba in both files)
both files may be located at any place in the pc so the path should be hardcoded in the macro(so i can change it as per my needs)
Thnx For the Help
2 Attachment(s)
condition not matched then delete entire row(Macro Correction)
Hi Experts,
Code:
Sub STEP6()
Dim Wb1 As Workbook, Wb2 As Workbook
Dim Ws1 As Worksheet, Ws2 As Worksheet
Dim Lr1 As Long, Lr2 As Long: Let Lr1 = 5000: Lr2 = 5000
Set Wb1 = Workbooks.Open("C:\Users\WolfieeeStyle\Desktop\1.xls")
Set Ws1 = Wb1.Worksheets(1)
Set Wb2 = Workbooks.Open("C:\Users\WolfieeeStyle\Desktop\Files\Error.xlsx")
Set Ws2 = Wb2.Worksheets(1)
Dim rngSrch As Range: Set rngSrch = Ws2.Range("C1:C" & Lr2 & "")
Dim rngDta As Range: Set rngDta = Ws1.Range("B2:B" & Lr1 & "")
Dim Cnt As Long
For Cnt = Lr2 To 1 Step -1
Dim MtchedCel As Variant
Set MtchedCel = rngSrch.Find(what:=rngDta.Item(Cnt), After:=rngSrch.Item(1), LookIn:=xlValues, LookAt:=xlWhole, SearchDirection:=xlNext, MatchCase:=True)
If Not MtchedCel Is Nothing Then
rngDta.Rows(Cnt).EntireRow.Delete Shift:=xlUp
Else
End If
Next Cnt
Wb1.Close SaveChanges:=True
Wb2.Close SaveChanges:=True
End Sub
This code has limitation of LR1=5000 & LR2= 5000(plz remove the limitations of this macro)
& one more issue is there with this macro
I am sending the sample file plz run the macro & see the output
If error.xlsx is blank sheet then it is giving something different output plz see
2 Attachment(s)
Delete Entire row by vba (macro Correction)
Code:
Sub ApplciationProgram()
Application.ScreenUpdating = False
Dim wb1 As Workbook
Dim wb2 As Workbook
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Dim RowCount1 As Integer
Dim ColumnCount1 As Integer
Dim RowCount2 As Integer
Dim ColumnCount2 As Integer
Dim OnemyArray() As Variant
Dim TwomyArray() As Variant
Dim RowCount As Integer
Dim sheetNumber As Integer
Dim rowNumber As Integer
Dim stateFlag As Boolean
Dim RowNumbers() As Variant
Dim Counter As Integer
stateFlag = False
While (Not stateFlag)
TwoExcellFilePath = "C:\Users\WolfieeeStyle\Desktop\HotStocks\AlertCodes.xlsx"
sheetNumber = 4
Set wb1 = ActiveWorkbook
Set ws1 = wb1.Sheets(3)
RowCount1 = ws1.UsedRange.Rows.Count
ColumnCount1 = ws1.UsedRange.Columns.Count
OnemyArray = ws1.Range("A1:H" & RowCount1).Value
Set wb2 = Workbooks.Open(filename:=TwoExcellFilePath)
Set ws2 = wb2.Sheets(sheetNumber)
RowCount2 = ws2.UsedRange.Rows.Count
ColumnCount2 = ws2.UsedRange.Columns.Count
RowCount = RowCount2
TwomyArray = ws2.Range("A1:K" & RowCount2).Value
wb2.Close SaveChanges:=True
Set wb2 = Nothing
Counter = 0
ReDim RowNumbers(RowCount1)
For i = 2 To RowCount1
For j = 1 To RowCount2
If (ws1.Cells(i, 5) = TwomyArray(j, 2) And ws1.Cells(i, 3) = TwomyArray(j, 4)) Then
ws1.Rows(i).EntireRow.Delete
RowCount1 = ws1.UsedRange.Rows.Count
End If
Next
Next
wb1.Save
Set wb1 = Nothing
Exit Sub
Wend
Application.ScreenUpdating = True
Exit Sub
End Sub
Function copyFiles(source As String, destination As String)
Dim fso As Object
Dim strFileExists As String
Set fso = CreateObject("scripting.filesystemobject")
strFileExists = Dir(source)
If strFileExists > "" Then
fso.movefile source:=source, destination:=destination
Else
MsgBox "File does not exists to copy"
End If
End Function
Function SplitWord(text As String) As String
Dim indexPoint As Integer
indexPoint = InStr(text, "-EQ")
SplitWord = Left(text, indexPoint - 1)
End Function
I have a macro to do the same but it is not deleting the entire row so plz see & help me out in the same
https://www.excelforum.com/excel-pro...orrection.html