Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
copy data if data exists
I have a sheet with x numbers of rows that i need to copy to another sheet.
If it was row 1 - 5 each time that woudl be fine but it dynamically changes. how do i select only the rows that have data? Second question. I have data in x numbers of rows and i want to add a "1" in an empty column but only where data exists in the rows. How can this be done? Thanks. dm. |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
copy data if data exists
Assuming your data starts in Cell A1 then Answer1:
Dim eRow As Long eRow = Cells(Rows.Count, 1).End(xlUp).Row Rows("1:" & eRow).EntireRow.Copy Destination:=Sheets(2).Range("A1") Answer2: Dim eRow As Long Dim eCol As Integer eRow = Cells(Rows.Count, 1).End(xlUp).Row eCol = Cells(1, Columns.Count).End(xlToLeft).Column + 1 Range(Cells(1, eCol), Cells(eRow, eCol)).Value = 1 Hope this helps Rowan "Daniel M" wrote: I have a sheet with x numbers of rows that i need to copy to another sheet. If it was row 1 - 5 each time that woudl be fine but it dynamically changes. how do i select only the rows that have data? Second question. I have data in x numbers of rows and i want to add a "1" in an empty column but only where data exists in the rows. How can this be done? Thanks. dm. |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
copy data if data exists
Rowan,
Both solutions work as requested but the second one is not exactly what i was looking for. Here is a better description... I have data like this... x y z x z x z Now everywhere y is missing i need to copy y. So i need to copy the contents of y down to every open cell down to the row that data stops. any help with this one? dm. "Rowan" <rowanzsa at hotmailNOSPAM dot com wrote in message ... Assuming your data starts in Cell A1 then Answer1: Dim eRow As Long eRow = Cells(Rows.Count, 1).End(xlUp).Row Rows("1:" & eRow).EntireRow.Copy Destination:=Sheets(2).Range("A1") Answer2: Dim eRow As Long Dim eCol As Integer eRow = Cells(Rows.Count, 1).End(xlUp).Row eCol = Cells(1, Columns.Count).End(xlToLeft).Column + 1 Range(Cells(1, eCol), Cells(eRow, eCol)).Value = 1 Hope this helps Rowan "Daniel M" wrote: I have a sheet with x numbers of rows that i need to copy to another sheet. If it was row 1 - 5 each time that woudl be fine but it dynamically changes. how do i select only the rows that have data? Second question. I have data in x numbers of rows and i want to add a "1" in an empty column but only where data exists in the rows. How can this be done? Thanks. dm. |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
copy data if data exists
Hi Daniel
Assuming your data is in the first three columns, starting in Row 2 there are a few ways to do this. If you simply want to copy the value (or formula) from cell B2 down to the end of you data then this should do it: Dim eRow As Long eRow = Cells(Rows.Count, 1).End(xlUp).Row Range("B2").Copy Destination:=Range(Cells(2, 2), Cells(eRow, 2)) That will replace anything that is already in Column B with whatever comes from B2. If there are data (or formulas) in other cells in column B that you do not want to replace then this will fill in only the blank cells: Dim eRow As Long eRow = Cells(Rows.Count, 1).End(xlUp).Row Range("B2").Copy Destination:=Range(Cells(2, 2), Cells(eRow, 2)). _ SpecialCells(xlCellTypeBlanks) Be aware that the second option will only work correctly if you have less than 8193 non-contiguos ranges in Column B. If you have more than 8192 non-contiguous ranges then all data/formulae in column B will be replaced by B2. Hope this helps Rowan "Daniel M" wrote: Rowan, Both solutions work as requested but the second one is not exactly what i was looking for. Here is a better description... I have data like this... x y z x z x z Now everywhere y is missing i need to copy y. So i need to copy the contents of y down to every open cell down to the row that data stops. any help with this one? dm. "Rowan" <rowanzsa at hotmailNOSPAM dot com wrote in message ... Assuming your data starts in Cell A1 then Answer1: Dim eRow As Long eRow = Cells(Rows.Count, 1).End(xlUp).Row Rows("1:" & eRow).EntireRow.Copy Destination:=Sheets(2).Range("A1") Answer2: Dim eRow As Long Dim eCol As Integer eRow = Cells(Rows.Count, 1).End(xlUp).Row eCol = Cells(1, Columns.Count).End(xlToLeft).Column + 1 Range(Cells(1, eCol), Cells(eRow, eCol)).Value = 1 Hope this helps Rowan "Daniel M" wrote: I have a sheet with x numbers of rows that i need to copy to another sheet. If it was row 1 - 5 each time that woudl be fine but it dynamically changes. how do i select only the rows that have data? Second question. I have data in x numbers of rows and i want to add a "1" in an empty column but only where data exists in the rows. How can this be done? Thanks. dm. |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
copy data if data exists
Rowan,
Great! this works better, and now that i have placed with the numbers and understand it i can use it for different columns. Now the only problem i have is that one of my cells has the formula =Sheet1!C5 in it and when it copies the data it changes the formula to C5, C6, C7 etc...Is there a way to only copy C5? Thanks. "Rowan" <rowanzsa at hotmailNOSPAM dot com wrote in message ... Hi Daniel Assuming your data is in the first three columns, starting in Row 2 there are a few ways to do this. If you simply want to copy the value (or formula) from cell B2 down to the end of you data then this should do it: Dim eRow As Long eRow = Cells(Rows.Count, 1).End(xlUp).Row Range("B2").Copy Destination:=Range(Cells(2, 2), Cells(eRow, 2)) That will replace anything that is already in Column B with whatever comes from B2. If there are data (or formulas) in other cells in column B that you do not want to replace then this will fill in only the blank cells: Dim eRow As Long eRow = Cells(Rows.Count, 1).End(xlUp).Row Range("B2").Copy Destination:=Range(Cells(2, 2), Cells(eRow, 2)). _ SpecialCells(xlCellTypeBlanks) Be aware that the second option will only work correctly if you have less than 8193 non-contiguos ranges in Column B. If you have more than 8192 non-contiguous ranges then all data/formulae in column B will be replaced by B2. Hope this helps Rowan "Daniel M" wrote: Rowan, Both solutions work as requested but the second one is not exactly what i was looking for. Here is a better description... I have data like this... x y z x z x z Now everywhere y is missing i need to copy y. So i need to copy the contents of y down to every open cell down to the row that data stops. any help with this one? dm. "Rowan" <rowanzsa at hotmailNOSPAM dot com wrote in message ... Assuming your data starts in Cell A1 then Answer1: Dim eRow As Long eRow = Cells(Rows.Count, 1).End(xlUp).Row Rows("1:" & eRow).EntireRow.Copy Destination:=Sheets(2).Range("A1") Answer2: Dim eRow As Long Dim eCol As Integer eRow = Cells(Rows.Count, 1).End(xlUp).Row eCol = Cells(1, Columns.Count).End(xlToLeft).Column + 1 Range(Cells(1, eCol), Cells(eRow, eCol)).Value = 1 Hope this helps Rowan "Daniel M" wrote: I have a sheet with x numbers of rows that i need to copy to another sheet. If it was row 1 - 5 each time that woudl be fine but it dynamically changes. how do i select only the rows that have data? Second question. I have data in x numbers of rows and i want to add a "1" in an empty column but only where data exists in the rows. How can this be done? Thanks. dm. |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
copy data if data exists
Change the original formula to =Sheet1!$C$5.
Regards Rowan "Daniel M" wrote: Rowan, Great! this works better, and now that i have placed with the numbers and understand it i can use it for different columns. Now the only problem i have is that one of my cells has the formula =Sheet1!C5 in it and when it copies the data it changes the formula to C5, C6, C7 etc...Is there a way to only copy C5? Thanks. "Rowan" <rowanzsa at hotmailNOSPAM dot com wrote in message ... Hi Daniel Assuming your data is in the first three columns, starting in Row 2 there are a few ways to do this. If you simply want to copy the value (or formula) from cell B2 down to the end of you data then this should do it: Dim eRow As Long eRow = Cells(Rows.Count, 1).End(xlUp).Row Range("B2").Copy Destination:=Range(Cells(2, 2), Cells(eRow, 2)) That will replace anything that is already in Column B with whatever comes from B2. If there are data (or formulas) in other cells in column B that you do not want to replace then this will fill in only the blank cells: Dim eRow As Long eRow = Cells(Rows.Count, 1).End(xlUp).Row Range("B2").Copy Destination:=Range(Cells(2, 2), Cells(eRow, 2)). _ SpecialCells(xlCellTypeBlanks) Be aware that the second option will only work correctly if you have less than 8193 non-contiguos ranges in Column B. If you have more than 8192 non-contiguous ranges then all data/formulae in column B will be replaced by B2. Hope this helps Rowan "Daniel M" wrote: Rowan, Both solutions work as requested but the second one is not exactly what i was looking for. Here is a better description... I have data like this... x y z x z x z Now everywhere y is missing i need to copy y. So i need to copy the contents of y down to every open cell down to the row that data stops. any help with this one? dm. "Rowan" <rowanzsa at hotmailNOSPAM dot com wrote in message ... Assuming your data starts in Cell A1 then Answer1: Dim eRow As Long eRow = Cells(Rows.Count, 1).End(xlUp).Row Rows("1:" & eRow).EntireRow.Copy Destination:=Sheets(2).Range("A1") Answer2: Dim eRow As Long Dim eCol As Integer eRow = Cells(Rows.Count, 1).End(xlUp).Row eCol = Cells(1, Columns.Count).End(xlToLeft).Column + 1 Range(Cells(1, eCol), Cells(eRow, eCol)).Value = 1 Hope this helps Rowan "Daniel M" wrote: I have a sheet with x numbers of rows that i need to copy to another sheet. If it was row 1 - 5 each time that woudl be fine but it dynamically changes. how do i select only the rows that have data? Second question. I have data in x numbers of rows and i want to add a "1" in an empty column but only where data exists in the rows. How can this be done? Thanks. dm. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
how to lookup if value exists in a range of data? | Excel Worksheet Functions | |||
Lookup only when data exists in table | Excel Discussion (Misc queries) | |||
do not copy data to another sheet if exists | Excel Worksheet Functions | |||
how to copy old price data onto new stock list if match exists? | Excel Discussion (Misc queries) | |||
Printing Worksheet only if data exists | Excel Programming |