Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 38
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 38
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 38
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to lookup if value exists in a range of data? S.elhalaby Excel Worksheet Functions 3 May 5th 23 07:43 PM
Lookup only when data exists in table BabyMc[_2_] Excel Discussion (Misc queries) 1 June 9th 09 11:52 AM
do not copy data to another sheet if exists Paul Excel Worksheet Functions 1 November 2nd 06 08:48 PM
how to copy old price data onto new stock list if match exists? julan Excel Discussion (Misc queries) 2 June 28th 05 03:49 PM
Printing Worksheet only if data exists oakman[_2_] Excel Programming 3 May 6th 04 02:08 PM


All times are GMT +1. The time now is 11:51 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"