ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Breaking down my macros into pieces (https://www.excelbanter.com/excel-programming/450781-breaking-down-my-macros-into-pieces.html)

B Roberson

Breaking down my macros into pieces
 
I tried laying out a project and asking for help but no one responded so I will attempt to break it down which means I will have a lot of small posts mainly showing my attempt at the context of what I am trying to do. I apologize, it has been quite a few years since I built a project like this. I am trying to adapt macro pieces I have saved over the years but I am rusty on the specifics. So here goes.



Dim Totalrows As Integer
Totalrows = Cells(Rows.Count, "A").End(xlUp).Row


I want to modify the command above to start at a specific cell which I have identified as a range Start. I want the variable Totalrows which I have current defined as a integer to record a number of rows from this first row to the last row that has records.

I tried modifying where it says "A" to be Range("Start") but that is not working, and right now it looks like

Crows = Cells(Rows.Count, Range("Start").End(xlUp).Row

Once I have this value of total rows for the range I am processing, then I can start a loop that will process until this variable totalrows is reached..



Can you get me going here please?

Thanks,


BR

GS[_2_]

Breaking down my macros into pieces
 
I tried laying out a project and asking for help but no one responded
so I will attempt to break it down which means I will have a lot of
small posts mainly showing my attempt at the context of what I am
trying to do. I apologize, it has been quite a few years since I
built a project like this. I am trying to adapt macro pieces I have
saved over the years but I am rusty on the specifics. So here goes.



Dim Totalrows As Integer
Totalrows = Cells(Rows.Count, "A").End(xlUp).Row


I want to modify the command above to start at a specific cell which
I have identified as a range Start. I want the variable Totalrows
which I have current defined as a integer to record a number of rows
from this first row to the last row that has records.


Row indexes are type Long, not Integer because the number of rows on a
worksheet exceeds the range of Integer!

I tried modifying where it says "A" to be Range("Start") but that is
not working, and right now it looks like


The "A" denotes which column to check last row in when using the
Cells() function.

Crows = Cells(Rows.Count, Range("Start").End(xlUp).Row

Once I have this value of total rows for the range I am processing,
then I can start a loop that will process until this variable
totalrows is reached.


Dim lLastRow As Long, lStartRow As Long, rng As Range

lStartRow = Range("Start").Cells(1).Row
lLastRow = Cells(Rows.Count, "A").End(xlUp).Row

Set rng = Range(Cells(lStartRow, "A"), Cells(lLastRow, "A"))

OR

Set rng = Range( "A" & lStartRow, "A" & lLastRow)

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion



B Roberson

Breaking down my macros into pieces
 
On Monday, April 13, 2015 at 12:12:14 PM UTC-5, GS wrote:
I tried laying out a project and asking for help but no one responded
so I will attempt to break it down which means I will have a lot of
small posts mainly showing my attempt at the context of what I am
trying to do. I apologize, it has been quite a few years since I
built a project like this. I am trying to adapt macro pieces I have
saved over the years but I am rusty on the specifics. So here goes.



Dim Totalrows As Integer
Totalrows = Cells(Rows.Count, "A").End(xlUp).Row


I want to modify the command above to start at a specific cell which
I have identified as a range Start. I want the variable Totalrows
which I have current defined as a integer to record a number of rows
from this first row to the last row that has records.


Row indexes are type Long, not Integer because the number of rows on a
worksheet exceeds the range of Integer!

I tried modifying where it says "A" to be Range("Start") but that is
not working, and right now it looks like


The "A" denotes which column to check last row in when using the
Cells() function.

Crows = Cells(Rows.Count, Range("Start").End(xlUp).Row

Once I have this value of total rows for the range I am processing,
then I can start a loop that will process until this variable
totalrows is reached.


Dim lLastRow As Long, lStartRow As Long, rng As Range

lStartRow = Range("Start").Cells(1).Row
lLastRow = Cells(Rows.Count, "A").End(xlUp).Row

Set rng = Range(Cells(lStartRow, "A"), Cells(lLastRow, "A"))

OR

Set rng = Range( "A" & lStartRow, "A" & lLastRow)

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


Thanks Garry


All times are GMT +1. The time now is 05:49 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com