Pages

Friday, March 23, 2012

Copying a range

Sub copyrange2()

    Range("a1:a5").Copy Range("b1")

End Sub

Moving a range

Sub MoveRange2()

    Range("A1:c6").Cut Range("a10")

End Sub

current region property

Sub currentRegionProperty()

    Selection.CurrentRegion.Select

End Sub

Sub copycurrentRegion2()

    Range("a1").CurrentRegion.Copy Sheets("sheet2").Range("a1")

    Application.CutCopyMode = False

End Sub

---------------------------------------------------------------------------------------------------------------------

Special cells

Sub special_cells()

    On Error Resume Next

    MsgBox Range("a1:c10").SpecialCells(xlCellTypeBlanks).Count

    MsgBox Range("a1:c10").SpecialCells(xlCellTypeComments).Count

    MsgBox Range("a1:c10").SpecialCells(xlCellTypeConstants).Count

    MsgBox Range("a1:c10").SpecialCells(xlCellTypeFormulas).Count

    MsgBox Range("a1:c10").SpecialCells(xlCellTypeVisible).Count

End Sub

 

Sub skipblaks()

    Dim constantcells As Range

    Dim formulacells As Range

   Dim cell As Range

    On Error Resume Next

   

    Set constantcells = Selection.SpecialCells(xlConstants)

    For Each cell In constantcells

        If cell.Value > 0 Then

            cell.Interior.Color = vbRed

        End If

    Next

   

    Set formulacells = seletion.SpecialCells(xlFormulas)

    For Each cell In formulacells

        If cell.Value > 0 Then

            cell.Interior.Color = vbRed

        End If

    Next

End Sub

Used Range

Sub Used_Range()

    MsgBox ActiveSheet.UsedRange.Address

    ActiveSheet.UsedRange.Select

    Dim ws As Worksheet

    Set ws = Sheets("sheet1")

    MsgBox ws.UsedRange.Rows.Count

    MsgBox ws.UsedRange.Columns.Count

    MsgBox ws.UsedRange.Cells.Count

    MsgBox ws.UsedRange.Cells(1, 1).Address

    MsgBox ws.UsedRange.Cells(1, 1).Row

    MsgBox ws.UsedRange.Cells(1, 1).Column

End Sub

End Method

Sub selectDown()

    Range(ActiveCell, ActiveCell.End(xlDown)).Select

End Sub

Sub MakeBold()

    Range(ActiveCell, ActiveCell.End(xlDown)).Font.Bold = True

End Sub

 

EntireColumn /Row property

Sub selectcolume()

    ActiveCell.EntireColumn.Select

End Sub

Prompting for a cell value

Sub getvalue()

    Dim x As Variant

    x = InputBox("enter the value for cell a1")

    If x <> "" Then Range("a1").Value = x

End Sub

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Sub checkseletion()

    Range("a1:c9").Select

    If TypeName(Selection) <> "range" Then

        MsgBox "select a range."

        Exit Sub

    End If

End Sub

 

No comments:

Post a Comment