WorkSheets(1).Range("A1").
Value = "Hola"
ActiveSheet.Range("A1").Value = "Hola"
ActiveSheet.ActiveCell.Value = "Hola"
Application.WorkBooks(1).WorkSheets(1).Range("A1").Value = "Hola"
ActiveSheet.Cells(1,1).Value="Hola"
ActiveSheet.Range(Casilla_Inicial).Cells(Fila, 1).Value = i
ActiveSheet.Range("A1").Offset(2, 2).Value = "Hola"
ActiveCell.Offset(2,2).Activate
ActiveSheet.Cells(Fila, Columna).Value = i
ActiveSheet.Range("A1").Offset(2, 2).Value = "Hola" ' Casilla C3 = Hola, 2 filas y 2
columnas desde A1.
ActiveCell.Offset(5,1).Value = "Hola" ' 5 Filas por debajo de la casilla Activa = Hola
‘ Buscar la primera celda vacía de la columna A y convertirla en activa
Do While Not IsEmpty(ActiveCell)
ActiveCell.Offset(1,0).Activate
Loop
Sub ReplaceTitleBar()
' Place the current files path and filename in the titlebar:
Windows(1).Caption = (ActiveWorkbook.FullName)
' Place your own application name in the titlebar:
Application.Caption = ("Your text here")
End Sub
Insert filename in a cell
Public Function ASAPFullFileName() As String
'i.e. [c:\test\file.xls]
Application.Volatile
ASAPFullFileName = ActiveWorkbook.FullName
End Function
Public Function ASAPFileName() As String
'i.e. [file.xls]
Application.Volatile
ASAPFileName = ActiveWorkbook.Name
End Function
Public Function ASAPFilePath() As String
'i.e. [c:\test]
Application.Volatile
ASAPFilePath = ActiveWorkbook.path
End Function
Velocidad de macros
' Turn off screenupdating:
Application.Screenupdating = False
Write data to a textfile
The following code will write data to a text file. If the file doesn't exist yet, it will be automaticly
created. The original text will be replaced every time the code is run.
Copy-paste friendly code:
Sub WriteToTextFile()
' writes data to a text file
' if the file does not exists, it will be created.
Dim iFileNumber As Integer
Dim msg As String
Dim strFileName As String
iFileNumber = FreeFile
msg = "Test data" 'the text written in the file
strFileName = "C:\test.txt" ' the text file
Open strFileName For Output As #iFileNumber
Print #iFileNumber, msg
Close #iFileNumber
End Sub
RANGOS Y MATRICES
Sub pasardatos()
Dim MiMatriz(1 To 10, 1 To 3)
Dim i As Integer, j As Integer
For i = 1 To 10
For j = 1 To 3
MiMatriz(i, j) = Worksheets("Hoja1").Cells(3 + i, j + 1).Value
Next j
Next i
End Sub
FORMA CORTA SE DEBE DIMENSIONAR LA MATRIZ COMO VARIANT
MiMatriz = [B4:D13]
o bien
MiMatriz = Range("B4:D13")
[F4:H13] = MiMatriz
o bien
Range("F4:H13") = MiMatriz
sELECCIONAR rANGO VARIABLE
Sub Prueba()
Dim Prueba As Integer
Dim Inicio As Integer
Inicio = 3
Prueba = 24
Range("A2:A" & Prueba).Select
End Sub
Hoja1.Range(Cells(a, b), Cells(c, d)).Select
LIBROS Y HOJAS
Workbooks("Libro2.xlsx").Activate
Workbooks("Cogs.xls").Worksheets("Sheet1").Activate
ActiveWorkbook.Author = "Jean Selva"
Worksheets("Sheet1").Activate
ActiveSheet.PageSetup.Orientation = xlLandscape
ActiveSheet.PrintOut
Worksheets("Sheet1").Range("A1").Value
For Each ws In Worksheets
MsgBox ws.Name
Next ws
RECORRER CELDAS DE UN RANGO
Dim rng As Range, cell As Range
Set rng = Range("A1:A3")
For Each cell In rng
Next cell
Set rng = Selection
SI NO ESTA LA CELDA VACIA
Sub DoStuffIfNotEmpty()
If Not IsEmpty(ActiveCell.Value) Then
MsgBox "I'm not empty!"
End If
End Sub
loop row until cell empty
1. Sub Test2()
2. ' Select cell B5, *first line of data*.
3. Range("B5").Select
4. ' Set Do loop to stop when an empty cell is reached.
5. Do Until IsEmpty(ActiveCell)
6. ' Insert your code here.
7. ' Step down 1 row from present location.
8. ActiveCell.Offset(1, 0).Select
9. Loop
10. End Sub