Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I working in an area on a spreadsheet that can have a variable number of
rows. The user can add and subtract rows, as needed. Now, I m developing a function that will "walk" down through these rows each time some data is changed. In the "static" number of rows, it's fairly easy. I just walk down through the rows, top to bottom, because I know exactly where the first row is and where the last row is. Now in the variable row case (real world) I don't know. I using a "Named" column and that will work except where the user adds a row at the very beginning or at the very end. The "Named" column doesn't pick up the new rows when they are added at the very beginning or the very end. So, I have changed the "Named" column to include the row immediately before and immediately after. Then I am safe. However, I still only want to search the rows of interest, so I am trying to find some way to adjust the size of the named column by changeing the beginning row to the next row(A3 - A4) and the end row up one (A304 - A303). If this is what I have to do, how do I do it? Or, perhaps you guys and gals can suggest a better way. Thanks very much for your help.. |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
One option is to use a dynamic named range defined using the OFFSET function.
YOu'll want something like this =OFFSET(A3, 1, 0, COUNTA(A:A), 1) A3 is the reference 1 row down from A3 0 columns to left or right of A3, Resize the range to be count of the non-empty cells in A. YOu may need to adjust this a bit. 1 column wide Adjust to suit. -- HTH, Barb Reinhardt "Bruce A. Julseth" wrote: I working in an area on a spreadsheet that can have a variable number of rows. The user can add and subtract rows, as needed. Now, I m developing a function that will "walk" down through these rows each time some data is changed. In the "static" number of rows, it's fairly easy. I just walk down through the rows, top to bottom, because I know exactly where the first row is and where the last row is. Now in the variable row case (real world) I don't know. I using a "Named" column and that will work except where the user adds a row at the very beginning or at the very end. The "Named" column doesn't pick up the new rows when they are added at the very beginning or the very end. So, I have changed the "Named" column to include the row immediately before and immediately after. Then I am safe. However, I still only want to search the rows of interest, so I am trying to find some way to adjust the size of the named column by changeing the beginning row to the next row(A3 - A4) and the end row up one (A304 - A303). If this is what I have to do, how do I do it? Or, perhaps you guys and gals can suggest a better way. Thanks very much for your help.. . |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Since I don't know what I'm talking about, maybe the following is not true.
I don't think "Resize the range to be count of the non-empty cells in A" will work because Rows [A3:A240] {240 Can Change) are the rows I am interested in. UNDER A240, is some other data that I don't want my function to reach. I HAVE TO stop at 240. That is why I thought giving my A column a name, one row above and one row below would solve the problem. To me it sounds a bit cluggy. I was wondering if there was a better way. Now that I have given you a bit more information, what do you think. Thanks for the response... "Barb Reinhardt" wrote in message ... One option is to use a dynamic named range defined using the OFFSET function. YOu'll want something like this =OFFSET(A3, 1, 0, COUNTA(A:A), 1) A3 is the reference 1 row down from A3 0 columns to left or right of A3, Resize the range to be count of the non-empty cells in A. YOu may need to adjust this a bit. 1 column wide Adjust to suit. -- HTH, Barb Reinhardt "Bruce A. Julseth" wrote: I working in an area on a spreadsheet that can have a variable number of rows. The user can add and subtract rows, as needed. Now, I m developing a function that will "walk" down through these rows each time some data is changed. In the "static" number of rows, it's fairly easy. I just walk down through the rows, top to bottom, because I know exactly where the first row is and where the last row is. Now in the variable row case (real world) I don't know. I using a "Named" column and that will work except where the user adds a row at the very beginning or at the very end. The "Named" column doesn't pick up the new rows when they are added at the very beginning or the very end. So, I have changed the "Named" column to include the row immediately before and immediately after. Then I am safe. However, I still only want to search the rows of interest, so I am trying to find some way to adjust the size of the named column by changeing the beginning row to the next row(A3 - A4) and the end row up one (A304 - A303). If this is what I have to do, how do I do it? Or, perhaps you guys and gals can suggest a better way. Thanks very much for your help.. . |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
If I understand you correctly, you want to take your named range and
reference the all the cells except the first and last one. If that is correct, you can reference those cells using something like this... Set InnerRange = Range("Named").Offset(1).Resize(Range("Named").Cou nt - 2) -- Rick (MVP - Excel) "Bruce A. Julseth" wrote in message ... Since I don't know what I'm talking about, maybe the following is not true. I don't think "Resize the range to be count of the non-empty cells in A" will work because Rows [A3:A240] {240 Can Change) are the rows I am interested in. UNDER A240, is some other data that I don't want my function to reach. I HAVE TO stop at 240. That is why I thought giving my A column a name, one row above and one row below would solve the problem. To me it sounds a bit cluggy. I was wondering if there was a better way. Now that I have given you a bit more information, what do you think. Thanks for the response... "Barb Reinhardt" wrote in message ... One option is to use a dynamic named range defined using the OFFSET function. YOu'll want something like this =OFFSET(A3, 1, 0, COUNTA(A:A), 1) A3 is the reference 1 row down from A3 0 columns to left or right of A3, Resize the range to be count of the non-empty cells in A. YOu may need to adjust this a bit. 1 column wide Adjust to suit. -- HTH, Barb Reinhardt "Bruce A. Julseth" wrote: I working in an area on a spreadsheet that can have a variable number of rows. The user can add and subtract rows, as needed. Now, I m developing a function that will "walk" down through these rows each time some data is changed. In the "static" number of rows, it's fairly easy. I just walk down through the rows, top to bottom, because I know exactly where the first row is and where the last row is. Now in the variable row case (real world) I don't know. I using a "Named" column and that will work except where the user adds a row at the very beginning or at the very end. The "Named" column doesn't pick up the new rows when they are added at the very beginning or the very end. So, I have changed the "Named" column to include the row immediately before and immediately after. Then I am safe. However, I still only want to search the rows of interest, so I am trying to find some way to adjust the size of the named column by changeing the beginning row to the next row(A3 - A4) and the end row up one (A304 - A303). If this is what I have to do, how do I do it? Or, perhaps you guys and gals can suggest a better way. Thanks very much for your help.. . |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
OK, then I have some other questions:
1) Does the data always start in A3? If not how do you know where it starts? 2) Is there data in every row after A3 until you get to A240 (or wherever it ends)? 3) How do you know when the data ends? Is there an empty cell in the next row? Barb Reinhardt "Bruce A. Julseth" wrote: Since I don't know what I'm talking about, maybe the following is not true. I don't think "Resize the range to be count of the non-empty cells in A" will work because Rows [A3:A240] {240 Can Change) are the rows I am interested in. UNDER A240, is some other data that I don't want my function to reach. I HAVE TO stop at 240. That is why I thought giving my A column a name, one row above and one row below would solve the problem. To me it sounds a bit cluggy. I was wondering if there was a better way. Now that I have given you a bit more information, what do you think. Thanks for the response... |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Yes, that is correct. I want to reference all the rows in my named range
except the first and last. Your suggestion "Looks" to me like it would work. You're taking my named range, Offset"ing" by 1 row and then resizing my name range by deleting 2 rows. I see you use "Set." When do I have to use set. I thought that went away with VB 3 or 4!! Thanks for the response. "Rick Rothstein" wrote in message ... If I understand you correctly, you want to take your named range and reference the all the cells except the first and last one. If that is correct, you can reference those cells using something like this... Set InnerRange = Range("Named").Offset(1).Resize(Range("Named").Cou nt - 2) -- Rick (MVP - Excel) "Bruce A. Julseth" wrote in message ... Since I don't know what I'm talking about, maybe the following is not true. I don't think "Resize the range to be count of the non-empty cells in A" will work because Rows [A3:A240] {240 Can Change) are the rows I am interested in. UNDER A240, is some other data that I don't want my function to reach. I HAVE TO stop at 240. That is why I thought giving my A column a name, one row above and one row below would solve the problem. To me it sounds a bit cluggy. I was wondering if there was a better way. Now that I have given you a bit more information, what do you think. Thanks for the response... "Barb Reinhardt" wrote in message ... One option is to use a dynamic named range defined using the OFFSET function. YOu'll want something like this =OFFSET(A3, 1, 0, COUNTA(A:A), 1) A3 is the reference 1 row down from A3 0 columns to left or right of A3, Resize the range to be count of the non-empty cells in A. YOu may need to adjust this a bit. 1 column wide Adjust to suit. -- HTH, Barb Reinhardt "Bruce A. Julseth" wrote: I working in an area on a spreadsheet that can have a variable number of rows. The user can add and subtract rows, as needed. Now, I m developing a function that will "walk" down through these rows each time some data is changed. In the "static" number of rows, it's fairly easy. I just walk down through the rows, top to bottom, because I know exactly where the first row is and where the last row is. Now in the variable row case (real world) I don't know. I using a "Named" column and that will work except where the user adds a row at the very beginning or at the very end. The "Named" column doesn't pick up the new rows when they are added at the very beginning or the very end. So, I have changed the "Named" column to include the row immediately before and immediately after. Then I am safe. However, I still only want to search the rows of interest, so I am trying to find some way to adjust the size of the named column by changeing the beginning row to the next row(A3 - A4) and the end row up one (A304 - A303). If this is what I have to do, how do I do it? Or, perhaps you guys and gals can suggest a better way. Thanks very much for your help.. . |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() 1) In general it starts in A3, but I can't be sure. That is why my named range starts one row above the rows of interest. 2) There is none useful data between my start and end rows, but I am able to avoid it in my row search 3) I don't know where it ends. That is why I am using a named range that is one row longer then what I need. That way, no matter where my customer enters or deletes rows, the name range will automatically adjust for these changes (I think!!) I think Rick Rothstein's suggestion will work. I'll give it a try a little later today.. Thanks for the response. "Barb Reinhardt" wrote in message ... OK, then I have some other questions: 1) Does the data always start in A3? If not how do you know where it starts? 2) Is there data in every row after A3 until you get to A240 (or wherever it ends)? 3) How do you know when the data ends? Is there an empty cell in the next row? Barb Reinhardt "Bruce A. Julseth" wrote: Since I don't know what I'm talking about, maybe the following is not true. I don't think "Resize the range to be count of the non-empty cells in A" will work because Rows [A3:A240] {240 Can Change) are the rows I am interested in. UNDER A240, is some other data that I don't want my function to reach. I HAVE TO stop at 240. That is why I thought giving my A column a name, one row above and one row below would solve the problem. To me it sounds a bit cluggy. I was wondering if there was a better way. Now that I have given you a bit more information, what do you think. Thanks for the response... |
#8
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I used the Set example because you didn't tell us how wanted to reference
the reduced range. Set is used to set a reference to an object (in VBA, Range is an object). So, in my example, you do this first... Set InnerRange = Range("Named").Offset(1).Resize(Range("Named").Cou nt - 2) and then in the rest of the procedure, you could simply use InnerRange (or any name you choose to call this object) to reference that range, for example... MsgBox InnerRange.Address Another choice is to use a With/End With block instead of Set'ting the reference. For example... With Range("Named").Offset(1).Resize(Range("Named").Cou nt - 2) MsgBox .Address End With What approach you use is up to you; but, again, you didn't tell us how you needed to use the reduced range, so I hade to make a guess. Oh, and if you declare your variables (which I think should always be done), you would Dim the InnerRange variable as Range. -- Rick (MVP - Excel) "Bruce A. Julseth" wrote in message ... Yes, that is correct. I want to reference all the rows in my named range except the first and last. Your suggestion "Looks" to me like it would work. You're taking my named range, Offset"ing" by 1 row and then resizing my name range by deleting 2 rows. I see you use "Set." When do I have to use set. I thought that went away with VB 3 or 4!! Thanks for the response. "Rick Rothstein" wrote in message ... If I understand you correctly, you want to take your named range and reference the all the cells except the first and last one. If that is correct, you can reference those cells using something like this... Set InnerRange = Range("Named").Offset(1).Resize(Range("Named").Cou nt - 2) -- Rick (MVP - Excel) "Bruce A. Julseth" wrote in message ... Since I don't know what I'm talking about, maybe the following is not true. I don't think "Resize the range to be count of the non-empty cells in A" will work because Rows [A3:A240] {240 Can Change) are the rows I am interested in. UNDER A240, is some other data that I don't want my function to reach. I HAVE TO stop at 240. That is why I thought giving my A column a name, one row above and one row below would solve the problem. To me it sounds a bit cluggy. I was wondering if there was a better way. Now that I have given you a bit more information, what do you think. Thanks for the response... "Barb Reinhardt" wrote in message ... One option is to use a dynamic named range defined using the OFFSET function. YOu'll want something like this =OFFSET(A3, 1, 0, COUNTA(A:A), 1) A3 is the reference 1 row down from A3 0 columns to left or right of A3, Resize the range to be count of the non-empty cells in A. YOu may need to adjust this a bit. 1 column wide Adjust to suit. -- HTH, Barb Reinhardt "Bruce A. Julseth" wrote: I working in an area on a spreadsheet that can have a variable number of rows. The user can add and subtract rows, as needed. Now, I m developing a function that will "walk" down through these rows each time some data is changed. In the "static" number of rows, it's fairly easy. I just walk down through the rows, top to bottom, because I know exactly where the first row is and where the last row is. Now in the variable row case (real world) I don't know. I using a "Named" column and that will work except where the user adds a row at the very beginning or at the very end. The "Named" column doesn't pick up the new rows when they are added at the very beginning or the very end. So, I have changed the "Named" column to include the row immediately before and immediately after. Then I am safe. However, I still only want to search the rows of interest, so I am trying to find some way to adjust the size of the named column by changeing the beginning row to the next row(A3 - A4) and the end row up one (A304 - A303). If this is what I have to do, how do I do it? Or, perhaps you guys and gals can suggest a better way. Thanks very much for your help.. . |
#9
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I am using my range in a For Each loop
Dim Cell as Range Dim InnerRange as Range For Each Cell in InnerRange next Cell And, I aways Dim my variables. I even have "manditory" dim define turned on. So, I am using it as an object. Where would I use "Range" when it is NOT an object. Thanks for the response "Rick Rothstein" wrote in message ... I used the Set example because you didn't tell us how wanted to reference the reduced range. Set is used to set a reference to an object (in VBA, Range is an object). So, in my example, you do this first... Set InnerRange = Range("Named").Offset(1).Resize(Range("Named").Cou nt - 2) and then in the rest of the procedure, you could simply use InnerRange (or any name you choose to call this object) to reference that range, for example... MsgBox InnerRange.Address Another choice is to use a With/End With block instead of Set'ting the reference. For example... With Range("Named").Offset(1).Resize(Range("Named").Cou nt - 2) MsgBox .Address End With What approach you use is up to you; but, again, you didn't tell us how you needed to use the reduced range, so I hade to make a guess. Oh, and if you declare your variables (which I think should always be done), you would Dim the InnerRange variable as Range. -- Rick (MVP - Excel) "Bruce A. Julseth" wrote in message ... Yes, that is correct. I want to reference all the rows in my named range except the first and last. Your suggestion "Looks" to me like it would work. You're taking my named range, Offset"ing" by 1 row and then resizing my name range by deleting 2 rows. I see you use "Set." When do I have to use set. I thought that went away with VB 3 or 4!! Thanks for the response. "Rick Rothstein" wrote in message ... If I understand you correctly, you want to take your named range and reference the all the cells except the first and last one. If that is correct, you can reference those cells using something like this... Set InnerRange = Range("Named").Offset(1).Resize(Range("Named").Cou nt - 2) -- Rick (MVP - Excel) "Bruce A. Julseth" wrote in message ... Since I don't know what I'm talking about, maybe the following is not true. I don't think "Resize the range to be count of the non-empty cells in A" will work because Rows [A3:A240] {240 Can Change) are the rows I am interested in. UNDER A240, is some other data that I don't want my function to reach. I HAVE TO stop at 240. That is why I thought giving my A column a name, one row above and one row below would solve the problem. To me it sounds a bit cluggy. I was wondering if there was a better way. Now that I have given you a bit more information, what do you think. Thanks for the response... "Barb Reinhardt" wrote in message ... One option is to use a dynamic named range defined using the OFFSET function. YOu'll want something like this =OFFSET(A3, 1, 0, COUNTA(A:A), 1) A3 is the reference 1 row down from A3 0 columns to left or right of A3, Resize the range to be count of the non-empty cells in A. YOu may need to adjust this a bit. 1 column wide Adjust to suit. -- HTH, Barb Reinhardt "Bruce A. Julseth" wrote: I working in an area on a spreadsheet that can have a variable number of rows. The user can add and subtract rows, as needed. Now, I m developing a function that will "walk" down through these rows each time some data is changed. In the "static" number of rows, it's fairly easy. I just walk down through the rows, top to bottom, because I know exactly where the first row is and where the last row is. Now in the variable row case (real world) I don't know. I using a "Named" column and that will work except where the user adds a row at the very beginning or at the very end. The "Named" column doesn't pick up the new rows when they are added at the very beginning or the very end. So, I have changed the "Named" column to include the row immediately before and immediately after. Then I am safe. However, I still only want to search the rows of interest, so I am trying to find some way to adjust the size of the named column by changeing the beginning row to the next row(A3 - A4) and the end row up one (A304 - A303). If this is what I have to do, how do I do it? Or, perhaps you guys and gals can suggest a better way. Thanks very much for your help.. . |
#10
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Assume your named "column" is named "theColumn". Try this:
Option Explicit Private Sub Worksheet_Change(ByVal Target As Excel.Range) Dim R As Range Set R = Range("theColumn").CurrentRegion.Columns("a") ThisWorkbook.Names.Add Name:="theColumn", RefersTo:=R End Sub This should make "theColumn" range include the newly added cells. HTH. "Bruce A. Julseth" wrote in message ... I working in an area on a spreadsheet that can have a variable number of rows. The user can add and subtract rows, as needed. Now, I m developing a function that will "walk" down through these rows each time some data is changed. In the "static" number of rows, it's fairly easy. I just walk down through the rows, top to bottom, because I know exactly where the first row is and where the last row is. Now in the variable row case (real world) I don't know. I using a "Named" column and that will work except where the user adds a row at the very beginning or at the very end. The "Named" column doesn't pick up the new rows when they are added at the very beginning or the very end. So, I have changed the "Named" column to include the row immediately before and immediately after. Then I am safe. However, I still only want to search the rows of interest, so I am trying to find some way to adjust the size of the named column by changeing the beginning row to the next row(A3 - A4) and the end row up one (A304 - A303). If this is what I have to do, how do I do it? Or, perhaps you guys and gals can suggest a better way. Thanks very much for your help.. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Newbie Question... | New Users to Excel | |||
Real Newbie newbie question | New Users to Excel | |||
Newbie Question - Subtraction Formula Question | Excel Discussion (Misc queries) | |||
Newbie question! | Excel Programming | |||
Newbie Question | Excel Programming |