#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default Blank cell


I have a worksheet with many rows, however, each of which is ended in
different column. For example, Row 1 ends in Column P, Row 2 ends in Column
C, Row 3 ends in Column E and so on. How can I move or copy the data in the
cell just before the blank cell using VB. Could someone help.

Thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Blank cell


Try

Activesheet.Usedrange.select

To copy from one sheet to another
Sheets("Sheet1").usedrange.copy Sheets("Sheet2").Range("A1")

If this post helps click Yes
---------------
Jacob Skaria


"AlanW" wrote:

I have a worksheet with many rows, however, each of which is ended in
different column. For example, Row 1 ends in Column P, Row 2 ends in Column
C, Row 3 ends in Column E and so on. How can I move or copy the data in the
cell just before the blank cell using VB. Could someone help.

Thanks

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Blank cell


You will need to find the last cell in the row with data for each row as you
attempt to move or copy.

Sub cpyNTLcell()
lr = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
rng = ActiveSheet.Range("A2:A" & lr)
For i = 2 To lr
ActiveSheet.Cells(i, Columns.Count).End(xlToLeft).Copy _
Sheets(2).Range("A" & i)
Next
End Sub

"AlanW" wrote:

I have a worksheet with many rows, however, each of which is ended in
different column. For example, Row 1 ends in Column P, Row 2 ends in Column
C, Row 3 ends in Column E and so on. How can I move or copy the data in the
cell just before the blank cell using VB. Could someone help.

Thanks

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Blank cell


Can you clarify your question a little bit please? Are you looking to move
the last piece of data (the data in the last cell) on each row? If so, where
did you want to move them... to a single column? Could there be any blank
rows in the data? Approximately how many rows (maximum) do you expect to be
doing this for (your answer will determine how complicated an approach to
take)?

--
Rick (MVP - Excel)


"AlanW" wrote in message
...
I have a worksheet with many rows, however, each of which is ended in
different column. For example, Row 1 ends in Column P, Row 2 ends in
Column
C, Row 3 ends in Column E and so on. How can I move or copy the data in
the
cell just before the blank cell using VB. Could someone help.

Thanks


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default Blank cell


Hello JLGWhiz,

You did what I intend to do, but can do me one more favour. Please show me
how to Move the data in last two cells just before the blank cell.

Thanks so much

"JLGWhiz" 來函:

You will need to find the last cell in the row with data for each row as you
attempt to move or copy.

Sub cpyNTLcell()
lr = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
rng = ActiveSheet.Range("A2:A" & lr)
For i = 2 To lr
ActiveSheet.Cells(i, Columns.Count).End(xlToLeft).Copy _
Sheets(2).Range("A" & i)
Next
End Sub

"AlanW" wrote:

I have a worksheet with many rows, however, each of which is ended in
different column. For example, Row 1 ends in Column P, Row 2 ends in Column
C, Row 3 ends in Column E and so on. How can I move or copy the data in the
cell just before the blank cell using VB. Could someone help.

Thanks

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
Average Formula to display blank cell if named range is blank Rachael F Excel Worksheet Functions 3 February 22nd 08 05:05 PM
Start Cell B1 then find first blank cell, insert subtotal, next non blank, then next blank, sutotal cells in between......... [email protected][_2_] Excel Programming 2 June 7th 07 09:27 PM
Need macro to check if cell is not blank & previous cell is blank, copy information from row above & paste JenIT Excel Programming 4 April 12th 07 08:56 PM
Copy to first Blank cell in Colum C Non blank cells still exist be Ulrik loves horses Excel Programming 2 October 8th 06 07:35 PM
COPY A CONCATENATE CELL TO BLANK CELL PUTTING IN THE NEXT BLANK C. QUEST41067 Excel Discussion (Misc queries) 1 January 15th 05 09:29 PM


All times are GMT +1. The time now is 10:17 PM.

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"