KEMBAR78
Columnas Desde A1.: Buscar La Primera Celda Vacía de La Columna A y Convertirla en Activa | PDF | Microsoft Excel | Computer Data
0% found this document useful (0 votes)
120 views4 pages

Columnas Desde A1.: Buscar La Primera Celda Vacía de La Columna A y Convertirla en Activa

The document provides code examples for performing various tasks in Excel VBA including: 1) Setting cell values on active sheets and worksheets. 2) Inserting the filename, filepath, and fullname into cells. 3) Writing data to a text file. 4) Selecting and activating ranges, cells, sheets, and workbooks. 5) Looping through cells and checking for empty values.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
120 views4 pages

Columnas Desde A1.: Buscar La Primera Celda Vacía de La Columna A y Convertirla en Activa

The document provides code examples for performing various tasks in Excel VBA including: 1) Setting cell values on active sheets and worksheets. 2) Inserting the filename, filepath, and fullname into cells. 3) Writing data to a text file. 4) Selecting and activating ranges, cells, sheets, and workbooks. 5) Looping through cells and checking for empty values.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

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

You might also like