VBA/Excel/Access/Word/Excel/Range Value — различия между версиями

Материал из VB Эксперт
Перейти к: навигация, поиск
м (1 версия)
 
м (1 версия)
 
(нет различий)

Текущая версия на 12:47, 26 мая 2010

Change cell A1 and move to cell A2 and change it

 
     Sub MyMacro()
         Range("A1").Value = "This is A1"
         Range("A2").Select
         ActiveCell.Value = "This is A2"
     End Sub



Clear NonDate Cells

 
Public Sub ClearNonDateCells()
  Dim aRange As Range
  For Each aRange In Cells.SpecialCells(xlCellTypeConstants, xlNumbers)
    If Not IsDate(aRange.Value) Then aRange.ClearContents
  Next aRange
End Sub



Reset value in a range to zero

 
Sub ResetValuesToZero2()
    For Each n In Worksheets("Sheet1").Range("WorkArea1")    "   Substitute your information here
        If n.Value <> 0 Then
            n.Value = 0
        End If
    Next n
End Sub



Return cell value in a range as an array

 
Sub Array3()
  Dim Data As Variant
  Data = Range("A1:A20").Value
  MsgBox "Number of Non Blank Elements = " & WorksheetFunction.CountA(Data) & vbCr
End Sub



Sum the range

 
Sub addAmtAbs()
    Set myRange = Range(ActiveCell, ActiveCell.End(xlUp))   "   Substitute your range here
    Dim myCount As Integer
    myCount = Application.Count(myRange)
    ActiveCell.Formula = "=SUM(B1:B" & myCount & ")"  "   Substitute your cell address here
End Sub



Transferring one-dimensional arrays with build-in function

 
Sub trans()
    range("A1:A3").value = Application.WorksheetFunction.Transpose(range("A1:C1"))
End Sub