Thank you for Visiting my Blog

Saturday, 27 May 2017

How to get Last used Rows & Cell in a column using VBA


There  are various methods to find Last Rows & Cell  in a Column. Below are few of them :
#First:
'Last Row  in Column A using .End method option:
 Sub LastRowInColumnA()

'Find the last used row in Column A

    Dim LastRow As Long
    With ActiveSheet
        LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
    End With
    MsgBox LastRow

End Sub
Note: Rows.Count will count all rows in the worksheet.
End(xlUp) will start at the last cell in the column and goes up until it finds the first non-blank cell.
#Second:
'Last Row in Column A using Rows:
Sub LastRows_Row_example()
    Dim LastRow As Long
    With ActiveSheet.UsedRange
        LastRow = .Rows(.Rows.Count).Row
    End With
    MsgBox LastRow

End Sub
#Third:
'Last Row  in Column A using . SpecialCells option
Sub SpecialCells_Example_Row()
    Dim LastRow As Long
    With ActiveSheet
        LastRow = .Range("A1").SpecialCells(xlCellTypeLastCell).Row
    End With
    MsgBox LastRow
End Sub
#Forth:
'Last Row in Column a using .Find option
 
 Sub Range_Find_Row()
'Finds the last non-blank cell on a sheet/range.
Dim lRow As Integer

    lRow = Cells.Find(What:="*", _
                    After:=Range("A1"), _
                    LookAt:=xlPart, _
                    LookIn:=xlFormulas, _
                    SearchOrder:=xlByRows, _
                    SearchDirection:=xlPrevious, _
                    MatchCase:=False).Row
   
    MsgBox "Last Row: " & lRow
End Sub
 
 
 
 

Saturday, 20 May 2017


To connect to HTML page through VBA , HTML object Library and Microsoft Internet Controls should be added to References. Below is the steps to add the references :

  • Go to Developer tab and click on Visual Basics



  • Once below screen opened .Go to the tools tab.



  • Right click on Tools and go to references.


  • It will give the list of the references available .Now search  HTML object Library and Microsoft Internet Controls  and check in the check box.

 Hope this will help you ...........


 

Tuesday, 16 May 2017

How to open Webpage using VBA

 
Hello Guys!!
 
below is the code to open webpage using VBA. Provide the URL which you wanted to open at below highlighted line . You even can change the browser as per your convenience.


Sub MyWebpage()

Dim ie As Object

    Set ie = CreateObject("INTERNETEXPLORER.APPLICATION")
    ie.Navigate "
https://www.google.co.in/"
   
      ie.Visible = True
    While ie.Busy
        DoEvents
   Wend



End Sub



Thank you !!!

Sunday, 7 May 2017

How to delete multiple worksheets in one click using Macro



Workbook Name : deletemultiplesheets.xlsm
Worksheet Name :Main
 
 I want to delete all the worksheets except worksheet "Main". Here is the solution  ...........
 Assign the below macro code to SUBMIT button . 


Sub deletemultiplesheets()
'--------------------- Delete multiple Worksheet in one click--------------------------


Dim wBook As Worksheet
Windows("deletemultiplesheets.xlsm").Activate
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False

    For Each wBook In Application.ActiveWorkbook.Worksheets
        If wBook.Name <> "Main" Then
       
        wBook.Delete
       
        End If
    Next
   
    Application.DisplayAlerts = True
    Application.ScreenUpdating = True
      
     
End Sub