You are on page 1of 2

To check a cell is blank or not , use the following command, because isempty can sometimes not work properly

 Isblank
 Len

To find correctly the last used row and the last used column in a sheet:

 LastRow = Cells.Find(what:="*", _
after:=Cells(1,), _
LookAt:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
 LastCol = Cells.Find(what:="*", _
after:=Cells(,1), _
LookAt:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Column
MsgBox LastRow
To check for coloured cells:
 cl.Interior.ColorIndex <> xlNone
To filter and work on the filtered range of cells:
 If sht2.AutoFilterMode = True Then
Else
sht2.Range("$J:$J").AutoFilter
End If
sht2.Range("$J$1:$J$" & LastRow1).AutoFilter Field:=1, Criteria1:=searchString
If sht2.AutoFilter.Range.Columns(10).SpecialCells(xlCellTypeVisible).Count > 1 Then
On Error GoTo hell
Set r = ActiveSheet.Range("$J$2:$J$" & LastRow1).Rows.SpecialCells(xlCellTypeVisible)
On Error GoTo 0
If Not r Is Nothing Then
StartRow = r.Row
Set body = Range(Cells(StartRow, 1), Cells(StartRow, 10))
For Each cl In body
If cl.Interior.ColorIndex <> xlNone Then
j = cl.Column
Str = "DVCA : " & Cells(StartRow, j).Value & Chr(10)
End If
Next cl
End If
End If
sht2.Range("J1").AutoFilter
To add an enter within a cell value with the VBA module programmation, use :
 Chr(10)
To delete all empty rows on a sheet:
 For i = LastRow To 1 Step -1
On Error Resume Next
If Application.CountA(Cells(i, 1).EntireRow) = 0 Then
Cells(i, 1).EntireRow.Delete
End If
To check if the file is open:
 Sub Test_Sub()
Dim myFilePath As String
myFilePath = "C:\Users\rchawla\Desktop\VBA\Reverse Tree Fill.xlsm"
If FileInUse(myFilePath) Then
MsgBox "File is Opened"
Else
MsgBox "File is Closed"
End If
End Sub
Public Function FileInUse(sFileName) As Boolean
On Error Resume Next
Open sFileName For Binary Access Read Lock Read As #1
Close #1
FileInUse = IIf(Err.Number > 0, True, False)
On Error GoTo 0
End Function

You might also like