Copy only nonblank cells


A

axcytz

Hi all,

I have an excel spreadsheet containing data like:

1 2 3 4
5 5
6
4 4 6 7 8 9 0
1 1 1

and so on.

What I want is to copy these values to a txt file. If I select all page, it copies the empty cells, too which causes some issues for my further coding stuff. Is there a way to copy only these nonblank cells?

Thanks for any help.
 
Ad

Advertisements

G

GS

it copies the empty cells, too which causes some issues for my further coding

What issues? Please elaborate because the code to write to the text
file can filter the blanks before doing so. Similarly, the code to read
from the text file can also filter the blanks. So either way you do it,
getting rid of the blanks is really no problem at all!

--
Garry

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

axcytz

What issues? Please elaborate because the code to write to the text

file can filter the blanks before doing so. Similarly, the code to read

from the text file can also filter the blanks. So either way you do it,

getting rid of the blanks is really no problem at all!



--

Garry



Free uenet access at http://www.eternal-september.org

Classic VB Users Regroup

comp.lang.basic.visual.misc

microsoft.public.vb.general.discussion

Each row has different number of data in excel. The problem is that when I copy from excel to txt, it seems like the blank cells contain some data. For example, in the below example, The second row has one element, but because of the first row, the blank cells in row 2 are also considered as data.

1 2 3
1
3 4
 
G

GS

Each row has different number of data in excel. The problem is that
when I copy from excel to txt, it seems like the blank cells contain
some data. For example, in the below example, The second row has one
element, but because of the first row, the blank cells in row 2 are
also considered as data.

1 2 3
1
3 4

I'm not sure but I'm guessing you're talking about elements in an array
created by loading the range into a variable. In this case those blank
cells are treated as 'Empty' elements in the array. I assume, then that
you don't want the 2nd line in the text file to contain a nullstring.
If that's the case then you need to remove them from the array before
writing to the file.

Personally, I don't see a problem with the nullstrings being there so
long as your parsing routine handles this correctly for your needs. I
also suspect you're not processing the data correctly for your needs
before writing it to file. Either way, I can't help you much without
seeing your entire code, so you need to post it for us to look at the
what/how of your process!

--
Garry

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

axcytz

I'm not sure but I'm guessing you're talking about elements in an array

created by loading the range into a variable. In this case those blank

cells are treated as 'Empty' elements in the array. I assume, then that

you don't want the 2nd line in the text file to contain a nullstring.

If that's the case then you need to remove them from the array before

writing to the file.



Personally, I don't see a problem with the nullstrings being there so

long as your parsing routine handles this correctly for your needs. I

also suspect you're not processing the data correctly for your needs

before writing it to file. Either way, I can't help you much without

seeing your entire code, so you need to post it for us to look at the

what/how of your process!



--

Garry



Free usenet access at http://www.eternal-september.org

Classic VB Users Regroup!

comp.lang.basic.visual.misc

microsoft.public.vb.general.discussion

I tried this:

crtl+A
Go to special
Constants
Numbers

These commands selects the nonblank cells but I cannot copy them. Is there a way to copy them?
 
Ad

Advertisements

G

GS

I tried this:
crtl+A
Go to special
Constants
Numbers

These commands selects the nonblank cells but I cannot copy them. Is
there a way to copy them?

This suggests you are doing this manually. This is not possible in this
manner when the data includes multiple selections.

Please explain better what exactly you want to do, and why your text
file can't include blanks for the import process later. Regardless, VBA
will do *exactly* what you want so long as you explain *exactly* what
that is!

--
Garry

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

axcytz

This suggests you are doing this manually. This is not possible in this

manner when the data includes multiple selections.



Please explain better what exactly you want to do, and why your text

file can't include blanks for the import process later. Regardless, VBA

will do *exactly* what you want so long as you explain *exactly* what

that is!



--

Garry



Free usenet access at http://www.eternal-september.org

Classic VB Users Regroup!

comp.lang.basic.visual.misc

microsoft.public.vb.general.discussion

I have vectors defined in c++, and I will read this txt file into my c++ code. When I copy from excel, the blank cells look like they have some data. That is, each row seems to have the same number of data, but this is not correct. Thus, I should choose the cells that have numbers in it to copy. I hope it is more clear now. Thanks for any help
 
Ad

Advertisements

G

GS

I have vectors defined in c++, and I will read this txt file into my
c++ code. When I copy from excel, the blank cells look like they have
some data. That is, each row seems to have the same number of data,
but this is not correct. Thus, I should choose the cells that have
numbers in it to copy. I hope it is more clear now. Thanks for any
help

I see! Excel (by default) will include all rows/cols that contain data.
As I explained before, any empty cells will be included in the array as
a result of this default behavior.

I'd be inclined to load the data into a variable that results in an
array that I can iterate that for non-empty data. The process would
build an array of arrays for output to a txt file, delimited by
whatever character I choose. (I see your data uses the space character,
which is also a default!) I suspect if you're proficient with C++ then
this should be a fairly trivial task<g>!

--
Garry

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top