Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 45
Default Copy data from above rows in cells are blank

Hi,

Wonder if someone can help me please.

I have quite a hefty amount of information in a spreadsheet, ranging from
columns A to I, rows 2 to 30,000, with column names in row 1.

Within this spreadsheet there are rows which have missing data. Can anyone
tell me please how I would go about developing a macro that when it come
across a blank row it copies the data from the above row and pastes it in the
blank row.

Many thanks

Chris

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Copy data from above rows in cells are blank

There is a fairly simple trick to doing this...

1. Find one of the empty cells and in that cell (For example A10) add the
formula to make it equal to the cell above (son in my example the formula in
A10 would be =A9)
2. Copy the cell where you have just added the formula.
3. Select the entire range A1:I30000
4. Hit F5 (or Ctrl+G) to bring up the Goto dialog
5. Click on the Special button
6. Select Blank Cells
7. All of the blank cells will now be highlighted.
8. Now paste the formula that you copied. (ctrl + V)
9. You may want to paste special values if you intend to resort the sheet.
--
HTH...

Jim Thomlinson


"ir26121973" wrote:

Hi,

Wonder if someone can help me please.

I have quite a hefty amount of information in a spreadsheet, ranging from
columns A to I, rows 2 to 30,000, with column names in row 1.

Within this spreadsheet there are rows which have missing data. Can anyone
tell me please how I would go about developing a macro that when it come
across a blank row it copies the data from the above row and pastes it in the
blank row.

Many thanks

Chris

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 45
Default Copy data from above rows in cells are blank

Jim,

Thanks for this. Even after using Excel for so long, it's amazing how much
you can still learn. This may also help me with something else I'm working
on.

Once again many thanks

Chris
"Jim Thomlinson" wrote:

There is a fairly simple trick to doing this...

1. Find one of the empty cells and in that cell (For example A10) add the
formula to make it equal to the cell above (son in my example the formula in
A10 would be =A9)
2. Copy the cell where you have just added the formula.
3. Select the entire range A1:I30000
4. Hit F5 (or Ctrl+G) to bring up the Goto dialog
5. Click on the Special button
6. Select Blank Cells
7. All of the blank cells will now be highlighted.
8. Now paste the formula that you copied. (ctrl + V)
9. You may want to paste special values if you intend to resort the sheet.
--
HTH...

Jim Thomlinson


"ir26121973" wrote:

Hi,

Wonder if someone can help me please.

I have quite a hefty amount of information in a spreadsheet, ranging from
columns A to I, rows 2 to 30,000, with column names in row 1.

Within this spreadsheet there are rows which have missing data. Can anyone
tell me please how I would go about developing a macro that when it come
across a blank row it copies the data from the above row and pastes it in the
blank row.

Many thanks

Chris

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 129
Default Copy data from above rows in cells are blank

Modify the range as needed. I have the "On Error..." to prevent
crashing when a blank is encountered in the offset cell. Maybe somebody
can help work around this if it causes problems.

Sub SameAsAbove()
'Copies data from cell above if current cell in range is blank
Dim MyRange As Range
Dim MyCell As Range
Dim Endrow As Integer
Endrow = Range("A65536").End(xlUp).Row
Set MyRange = Range("A1:G" & Endrow)
MyRange.Select
On Error Resume Next
For Each MyCell In MyRange
If MyCell.Value = "" Then
MyCell.Value = MyCell.Offset(-1, 0).Value
End If
Next MyCell
End Sub


ir26121973 wrote:
Hi,

Wonder if someone can help me please.

I have quite a hefty amount of information in a spreadsheet, ranging from
columns A to I, rows 2 to 30,000, with column names in row 1.

Within this spreadsheet there are rows which have missing data. Can anyone
tell me please how I would go about developing a macro that when it come
across a blank row it copies the data from the above row and pastes it in the
blank row.

Many thanks

Chris


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 45
Default Copy data from above rows in cells are blank

Thanks for taking the time to read this.

I've used it on some test data and it works a treat.

Thanks again

Chris

" wrote:

Modify the range as needed. I have the "On Error..." to prevent
crashing when a blank is encountered in the offset cell. Maybe somebody
can help work around this if it causes problems.

Sub SameAsAbove()
'Copies data from cell above if current cell in range is blank
Dim MyRange As Range
Dim MyCell As Range
Dim Endrow As Integer
Endrow = Range("A65536").End(xlUp).Row
Set MyRange = Range("A1:G" & Endrow)
MyRange.Select
On Error Resume Next
For Each MyCell In MyRange
If MyCell.Value = "" Then
MyCell.Value = MyCell.Offset(-1, 0).Value
End If
Next MyCell
End Sub


ir26121973 wrote:
Hi,

Wonder if someone can help me please.

I have quite a hefty amount of information in a spreadsheet, ranging from
columns A to I, rows 2 to 30,000, with column names in row 1.

Within this spreadsheet there are rows which have missing data. Can anyone
tell me please how I would go about developing a macro that when it come
across a blank row it copies the data from the above row and pastes it in the
blank row.

Many thanks

Chris





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 129
Default Copy data from above rows in cells are blank

Modify the range as needed. I have the "On Error..." to prevent
crashing when a blank is encountered in the offset cell. Maybe somebody
can help work around this if it causes problems.

Sub SameAsAbove()
'Copies data from cell above if current cell in range is blank
Dim MyRange As Range
Dim MyCell As Range
Dim Endrow As Integer
Endrow = Range("A65536").End(xlUp).Row
Set MyRange = Range("A1:G" & Endrow)
MyRange.Select
On Error Resume Next
For Each MyCell In MyRange
If MyCell.Value = "" Then
MyCell.Value = MyCell.Offset(-1, 0).Value
End If
Next MyCell
End Sub


ir26121973 wrote:
Hi,

Wonder if someone can help me please.

I have quite a hefty amount of information in a spreadsheet, ranging from
columns A to I, rows 2 to 30,000, with column names in row 1.

Within this spreadsheet there are rows which have missing data. Can anyone
tell me please how I would go about developing a macro that when it come
across a blank row it copies the data from the above row and pastes it in the
blank row.

Many thanks

Chris


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
copy data from one worksheet and disregard blank cells Allan Excel Discussion (Misc queries) 6 October 20th 08 07:40 AM
Removing blank cells in rows of data Andy in Edinburgh[_2_] Excel Worksheet Functions 8 September 8th 08 06:12 PM
How do I delete blank rows (rows alternate data, blank, data, etc ncochrax Excel Discussion (Misc queries) 2 June 27th 07 04:40 AM
Copy rows of data (eliminating blank rows) from fixed layout Sweepea Excel Discussion (Misc queries) 1 March 13th 07 11:05 PM
Copy rows of data to another worksheet where ReturnDate is blank Helen McClaine Excel Discussion (Misc queries) 2 March 28th 05 11:33 PM


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

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

About Us

"It's about Microsoft Excel"