![]() |
Macro reading new rows
Hi again, I already asked about this, however I still do not know where to put the lastrow (sorry but I am not very familiar with this programming language). I already did a macro with a certain number of rows. However, it still can not read the extra rows of a text file (with more rows than the ones I used to create the macro initially). Now I know that I could use "lastrow" to make my calculations, however, I still do not know how to include this command in my program. Currently, one part looks like the one showed below: a formula is developed in the range of cells from D2 to D7 however I would like to say, instead of D7, until the last row appears in the file. Thus, I still do not know how to make it. What should I change here (in my main program)? How the subroutine should look like,if so? Hope somebody can help me with this!!! Thanks in advance for your help, Karolina __________________________________________________ ______________ Selection.Delete Shift:=xlUp Columns("D:D").Select Selection.Insert Shift:=xlToRight Rows("1:1").Select Selection.Insert Shift:=xlDown Range("D2").Select ActiveCell.FormulaR1C1 = "=DATE(RC[-1],RC[-3],RC[-2])" Selection.AutoFill Destination:=Range("D2:D7"), Type:=xlFillDefault Range("D2:D7").Select -- Karolina ------------------------------------------------------------------------ Karolina's Profile: http://www.excelforum.com/member.php...o&userid=31600 View this thread: http://www.excelforum.com/showthread...hreadid=514059 |
Macro reading new rows
I think you just need to change the line that performs the fill. Assuming
you've already set the variable lastrow to indicate the final row that needs to be filled, use that to create the string which is the autofill range: Selection.AutoFill Destination:=Range("D2:D" & lastrow), Type:=xlFillDefault I'm not sure what's happening after the code you posted; if there are more operations made on the range selected as the end, that should be change similarly: Range("D2:D" & lastrow).Select --Bruce "Karolina" wrote: Hi again, I already asked about this, however I still do not know where to put the lastrow (sorry but I am not very familiar with this programming language). I already did a macro with a certain number of rows. However, it still can not read the extra rows of a text file (with more rows than the ones I used to create the macro initially). Now I know that I could use "lastrow" to make my calculations, however, I still do not know how to include this command in my program. Currently, one part looks like the one showed below: a formula is developed in the range of cells from D2 to D7 however I would like to say, instead of D7, until the last row appears in the file. Thus, I still do not know how to make it. What should I change here (in my main program)? How the subroutine should look like,if so? Hope somebody can help me with this!!! Thanks in advance for your help, Karolina __________________________________________________ ______________ Selection.Delete Shift:=xlUp Columns("D:D").Select Selection.Insert Shift:=xlToRight Rows("1:1").Select Selection.Insert Shift:=xlDown Range("D2").Select ActiveCell.FormulaR1C1 = "=DATE(RC[-1],RC[-3],RC[-2])" Selection.AutoFill Destination:=Range("D2:D7"), Type:=xlFillDefault Range("D2:D7").Select -- Karolina ------------------------------------------------------------------------ Karolina's Profile: http://www.excelforum.com/member.php...o&userid=31600 View this thread: http://www.excelforum.com/showthread...hreadid=514059 |
Macro reading new rows
Dim LastRow as long
'I'm not sure what this line does, 'cause it depends on what's selected Selection.Delete Shift:=xlUp 'no need to select a range to work on it. Columns("D:D").Insert Rows("1:1").Insert 'find that lastrow based on the data in column A LastRow = cells(rows.count,"A").end(xlup).row 'fill all of the range with the formula at one time. Range("D2:D" & lastrow).FormulaR1C1 = "=DATE(RC[-1],RC[-3],RC[-2])" Karolina wrote: Hi again, I already asked about this, however I still do not know where to put the lastrow (sorry but I am not very familiar with this programming language). I already did a macro with a certain number of rows. However, it still can not read the extra rows of a text file (with more rows than the ones I used to create the macro initially). Now I know that I could use "lastrow" to make my calculations, however, I still do not know how to include this command in my program. Currently, one part looks like the one showed below: a formula is developed in the range of cells from D2 to D7 however I would like to say, instead of D7, until the last row appears in the file. Thus, I still do not know how to make it. What should I change here (in my main program)? How the subroutine should look like,if so? Hope somebody can help me with this!!! Thanks in advance for your help, Karolina __________________________________________________ ______________ Selection.Delete Shift:=xlUp Columns("D:D").Select Selection.Insert Shift:=xlToRight Rows("1:1").Select Selection.Insert Shift:=xlDown Range("D2").Select ActiveCell.FormulaR1C1 = "=DATE(RC[-1],RC[-3],RC[-2])" Selection.AutoFill Destination:=Range("D2:D7"), Type:=xlFillDefault Range("D2:D7").Select -- Karolina ------------------------------------------------------------------------ Karolina's Profile: http://www.excelforum.com/member.php...o&userid=31600 View this thread: http://www.excelforum.com/showthread...hreadid=514059 -- Dave Peterson |
All times are GMT +1. The time now is 07:32 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com