Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel Spreadsheet - Move column content to another column

Status
Not open for further replies.

okeyuzosike

Programmer
Jun 15, 2007
15
US
Good morning gentlemen,
I am working with VB6. Please, I need your assistance. I have a spreadsheet with 4 columns containing data. The 5th column "E" has no data.
----A----- -B-- -C- ---D--- ---E---
Totalhours|Name|Age|Address|
---------- ---- --- -------|-------
0000000005|Jack| 35|New York

My objective is to check for any column that has no data, then MOVE the content of Column "A"(Totalhours) to the empty column. In this case, the empty column will be "E".

Pseudocode:

Check columns
If column has data, skip that column
Elseif column is empty Then
MOVE the content of Column A to the empty column
Endif.

After the process, the result should be like this:

-B-- -C- ---D--- ---E-----
Name|Age|Address|Totalhours
---------- ---- --- -------
Jack|35 |New York|000000005

Thank you all.
Okey.



 
Sounds a weird requirement. How will you know which column contains which data?
4 columns containing data. The 5th column "E" has no data.
check for any column that has no data, then MOVE the content of Column "A"(Totalhours) to the empty column
I assume that you mean that columns B,C, D or E might be empty.
I assume that if columns B and D are both empty you want the contents of Col A copied into BOTH B and D and then the existing column A deleted so that B becomes A, C becomes B etc?
I assume that the entire column has to be empty - or are you wanting to check through every row individually?
When you say 'move' do you mean that column B will become column A etc?
Is this something you need to regularly repeat or would a non VB solution be ok?


Gavin
 
Yes, you are right. I want to move the contents of column A to the empty column, then delete column A. The idea is that since I may not know which column does not have data in it, I want it to check ( like loop thru the columns)to find which column is empty, then move the sourcd to that destination, then delete the source - in this case column A.
Thanks.
Okey.
 
I finally accomplished the objective with the code below:
Dim i As integer

For i = 1 To 256
If Application.CountA(Range(Cells(1, i), Cells(65536, i))) = 0 Then
Columns(2).Cut Destination:=Columns(i)
Exit For
End If
Next i

Thanks everyone.
Okey.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top