Saltar al contenido
PROGRAMAR EN VBA MACROS DE EXCEL

Como determinar la última fila con datos


(adsbygoogle = window.adsbygoogle || []).push({});

Todo o casi todo aquel que esté en proceso de realizar o crear una macro, es muy probable que necesite saber como determinar la última fila con datos o como encontrar la primer fila libre, ya sea para determinar un rango para ordenar datos, establecer dicha fila para agregar datos o lo que se requiera hacer.

En el presente ejemplo de macro o código de VBA se muestra como determinar la última fila con datos, para ello existen varias formas la que se usará depende del los datos que tengamos la disposición de los mismos o la que mejor recordemos al momento de crear la macro.

Empecemos por la más sencilla:
uf = Sheets(«BY879VbDAYRA10iBIUYT»).Range(«D» & Rows.Count).End(xlUp).Row

Este código lo que hace es poner en la variable «uf» cual es la última fila con datos de la column D, luego se puede usar así:

Cells(uf, 2). Select

Este código está haciendo referencia o seleccionando la última celda de la columna dos o «B»; o de esta otra forma que también hace referencia o selecciona a la última celda de la columna «D».

Range(«D» & uf).Select  


También se puede utilizar un bucle para encontrar la última fila con datos, sin embargo supone un proceso mayor, ya que tiene que recorrer todas las filas hasta encontrarla, si son pocas no se nota el tiempo que tarda pero si son muchas la macro para determinar la última fila con datos tardará un poco.

Antes de seguir recomiendo leer un excelente libro sobre Excel que te ayudará operar las planillas u hojas de cálculo, haz click acá, si quieres aprender sobre Excel, en inglés, entonces debes hacer click here. Si lo que necesitas es aprender o profundizar sobre la programación de macros con VBA este es unos de los mejores cursos on line que he visto en internet.

  

Para determinar la fila vacía mediante un bucle se puede usar el siguiente código «ActiveCell.Offset(1, 0).Select»; con este código se irá seleccionando la fila siguiente a la actual, para luego mediante el bucle ir determinando la última fila con datos, ya que el mismo debe recorrer las celdas hasta que encuentre un celda vacía, el problema con este código es que si en medio existe una celda vacía no produciría un error ya que la macro se detendrá y no precisamente en la última celda con datos.

Por último te voy a mostrar un código que utiliza la última celda con datos para determinar hasta cuando realizar un procedimiento de recorrido y proceso de las celdas, lo que hace el código es ir poniendo las celdas en rojo si son menores a 5, el bucle se realiza hasta la última celda con datos, lo cual es determinado por el siguiente código: While ActiveCell <> Empty

Desde el link del final podrás  bajar el archivo de ejemplo para que puedas adaptarlo a tus necesidades, no olvides colaborar para seguir manteniendo esta web.

El vídeo que sigue muestra una explicación más detallada y gráfica de la macro presentada, recomiendo observar para una más fácil comprensión de la macro; suscribe a nuestra web desde la parte superior derecha de la página ingresando tu mail y a nuestro canal de You Tube para recibir en tu correo vídeos explicativos sobre macros interesantes, como  por ejemplo formulario que crea un listado de todas las hojas para poder luego seleccionarlasbuscar en listbox mientras escribes en textboxordenar hojas libro excel por su nombreconectar Excel con Access y muchos ejemplos más.


function onYtEvent(payload) {
if (payload.eventType == ‘subscribe’) {
// Add code to handle subscribe event.
} else if (payload.eventType == ‘unsubscribe’) {
// Add code to handle unsubscribe event.
}
if (window.console) { // for debugging only
window.console.log(‘YT event: ‘, payload);
}
}

 

Código que se inserta en un módulo


Sub uf()
Dim uf As Integer
uf = Sheets(«hoja1»).Range(«A» & Rows.Count).End(xlUp).Row
MsgBox («La última fila es la » & uf), vbInformation, «AVISO»
End Sub

Sub ufbucle()
Dim dir
While ActiveCell <> Empty
dir = ActiveCell.Address(False, False)
ActiveCell.Offset(1, 0).Select
Wend
MsgBox («La dirección de la última fila es » & dir), vbInformation, «AVISO»
End Sub

Sub bucle()
Dim fila, conta As Integer
fila = 2
Range(«C:C»).Interior.Pattern = xlNone
While Sheets(«hoja1»).Cells(fila, 3) <> Empty
 If Sheets(«hoja1»).Cells(fila, 3) < 5 Then
 Sheets(«hoja1»).Cells(fila, 3).Interior.Color = 255
 conta = conta + 1
 End If
fila = fila + 1
Wend
MsgBox («Se encontrarón » & conta & » casos»), vbInformation, «AVISO»
End Sub

Otros post de utilidad:

  1. Ordenar datos e insertar filas
  2. Ordenar datos al activar hoja
  3. Ordena en base a varias columnas
  4. Userform para ordenar datos que tiene combobox insertados
  5. Recuperar password de hoja bloqueada
  6. Función BUSCARV
  7. Función BUSCARH 
  8. Función SI
  9. Abre explorador de archivo de Windows e inserta foto
  10. Abre explorador de archivo de Windows
  11. Combobox suma datos repetidos
  12. Busca un dato en todas las hojas de excel
  13. Combobox incrustado en Excel
  14. Formulario para insertar datos en hoja de excel
  15. Formulario de alera y envío de mail
  16. Tutoriales sobre VBA
  17. Llenar combobox y buscar datos
  18. Mensaje de Alerta y envío de mail con Excel
  19. Combobox que lista hojas de excel y las selecciona
  20. Busca un dato en todas las hojas de excel

amzn_assoc_placement = «adunit0»;
amzn_assoc_enable_interest_ads = «true»;
amzn_assoc_tracking_id = «pevmpe-20»;
amzn_assoc_ad_mode = «auto»;
amzn_assoc_ad_type = «smart»;
amzn_assoc_marketplace = «amazon»;
amzn_assoc_region = «US»;
amzn_assoc_textlinks = «»;
amzn_assoc_linkid = «dd6af26f8beece4d0990598f92dbfebd»;
amzn_assoc_emphasize_categories = «16261631,51569011,2619525011,2617941011,15684181,165796011,3760911,1000,13900861,2335752011,36632,9003130011,13900871,130,172282,5088769011,979455011,2238192011,16310101,3760901,1055398,16310091,3367581,133140011,284507,195209011,599858,10272111,301668,51575011,1064954,2972638011,2619533011,672123011,229534,3375251,3250697011,228013,165793011,404272,468642,377110011»;
amzn_assoc_rows = «1»;
amzn_assoc_fallback_mode = {«type»:»search»,»value»:»fone, shoes, accesories»};
amzn_assoc_default_category = «All»;

Si te fue de utilidad puedes INVITARME UN CAFÉ y de esta manera ayudar a seguir manteniendo la página, CLICK para descargar en ejemplo en forma gratuita.


(adsbygoogle = window.adsbygoogle || []).push({});

If this post was helpful INVITE ME A COFFEE and so help keep up the page, CLICK to download free example.

Si te gustó por favor compártelo con tus amigos
If you liked please share it with your friends      

Entradas relacionadas

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *

Comentarios (30)

Hi there I am so happy I found your webpage, I really found you by mistake, while I was searching on Askjeeve for something
else, Nonetheless I am here now and would just like to
say many thanks for a remarkable post and a all round thrilling blog (I
also love the theme/design), I don’t have time to read through it all at the moment but I have book-marked
it and also added your RSS feeds, so when I have time I will be back to read
a great deal more, Please do keep up the excellent work.

Responder

I get pleasure from, lead to I discovered exactly what I was taking a look for.
You’ve ended my 4 day lengthy hunt! God Bless you man. Have
a great day. Bye

Responder

Hello there! I know this is kind of off topic but I was
wondering if you knew where I could find a captcha plugin for my comment
form? I’m using the same blog platform as yours
and I’m having trouble finding one? Thanks a lot!

Responder

Great beat ! I wish to apprentice while you amend your site, how could i subscribe for a blog web site?
The account aided me a acceptable deal. I had been tiny bit acquainted
of this your broadcast provided bright clear concept

Responder

Hey I know this is off topic but I was wondering if you knew of any widgets I could add to
my blog that automatically tweet my newest twitter updates.
I’ve been looking for a plug-in like this for quite some time and was hoping maybe you would
have some experience with something like this.
Please let me know if you run into anything. I truly enjoy reading your blog and I look forward to your new updates.

Responder

This website truly has all of the information and facts I needed
about this subject and didn’t know who to ask.

Responder

I’ve learn some excellent stuff here. Certainly worth bookmarking for
revisiting. I wonder how a lot attempt you place to create one of
these wonderful informative website.

Responder

Hi, I read your new stuff like every week.
Your writing style is awesome, keep up the
good work!

Responder

It’s a pity you don’t have a donate button! I’d without a doubt donate
to this brilliant blog! I guess for now i’ll settle for book-marking and adding your RSS feed to my Google account.
I look forward to new updates and will talk about this site with
my Facebook group. Chat soon!

Responder

What’s up to every one, the contents existing at this web site are actually amazing for people experience, well, keep up the good work fellows.

Responder

Highly energetic post, I liked that bit. Will there be a part 2?

Responder

Hi there just wanted to give you a quick heads up.
The text in your article seem to be running off the screen in Internet explorer.

I’m not sure if this is a format issue or something to do with internet browser compatibility but I thought I’d post to let you know.
The design look great though! Hope you get
the issue solved soon. Cheers

Responder

I’m extremely inspired with your writing skills and also with the layout for your blog.
Is that this a paid theme or did you modify it your self?
Either way stay up the nice quality writing, it is rare to look a great blog like this one today..

Responder

This blog was… how do you say it? Relevant!! Finally I have found something which helped me.
Thanks!

Responder

I love your blog.. very nice colors & theme. Did you make this website yourself or did you hire someone to do it for you?
Plz answer back as I’m looking to construct my own blog and
would like to know where u got this from. kudos

Responder

You really make it seem really easy along with your presentation however I to find this matter to be actually something which I feel I’d never
understand. It seems too complicated and very large for me.
I am looking forward on your subsequent submit,
I’ll attempt to get the cling of it!

Responder

If some one wants expert view on the topic of running a blog then i propose him/her to go to see this web
site, Keep up the pleasant job.

Responder

It’s going to be end of mine day, but before ending I am reading this impressive post to increase my know-how.

Responder

It is perfect time to make some plans for the future and
it’s time to be happy. I have read this post and if I
could I wish to suggest you few interesting things or suggestions.
Maybe you could write next articles referring to this article.

I want to read more things about it!

Responder

Wow! After all I got a blog from where I be able to actually obtain useful information concerning
my study and knowledge.

Responder

Thanks for sharing your info. I really appreciate your efforts and
I will be waiting for your next write ups thank you once
again.

Responder

Hi! Would you mind if I share your blog with my myspace
group? There’s a lot of people that I think would really
enjoy your content. Please let me know. Many thanks

Responder

Wow! Finally I got a blog from where I can in fact get useful data concerning my study and knowledge.

Responder

Howdy would you mind sharing which blog platform you’re
working with? I’m looking to start my own blog in the near future but I’m having a hard time deciding between BlogEngine/Wordpress/B2evolution and Drupal.

The reason I ask is because your layout seems different then most blogs and I’m looking for something unique.
P.S Sorry for getting off-topic but I had to ask!

Responder

Can you tell us more about this? I’d love to find out some additional information.

Responder

Hey just wanted to give you a quick heads up.
The text in your article seem to be running off the screen in Opera.
I’m not sure if this is a formatting issue or something to do with browser
compatibility but I figured I’d post to let you know. The design look great though!
Hope you get the issue solved soon. Many thanks

Responder

Hey I know this is off topic but I was wondering
if you knew of any widgets I could add to my blog that automatically tweet my newest twitter
updates. I’ve been looking for a plug-in like this for quite some time and was hoping maybe you would have some experience with
something like this. Please let me know if you run into anything.

I truly enjoy reading your blog and I look forward to your new updates.

Responder

Tremendous issues here. I’m very happy to look your post.

Thank you a lot and I am having a look forward to contact you.
Will you kindly drop me a mail?

Responder

Howdy would you mind letting me know which hosting company you’re utilizing?

I’ve loaded your blog in 3 different web browsers and I must say this blog loads a lot quicker then most.
Can you suggest a good internet hosting provider at a reasonable price?

Many thanks, I appreciate it!

Responder

Heya i’m for the first time here. I found this board and I to find It really helpful &
it helped me out much. I’m hoping to present one thing again and help others such as you aided me.

Responder