Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 59
Default Copy Paste Macro - Pls Help!

Hi I am trying to do a copy paste macro for a spread sheet a data
import that skips over a few fields. The spreadsheet is about 650 rows
so going through it manually is very tedious. I want the macro to be
able to copy paste when column "A" is blank the date from the row above
in columns A,B & D, E, F. It would look like this:

A B C D E F
as ad af ag ah ak
IT LO

After macro is run - seeing that column A is blank it would copy paste
from above to looke like this - Notice it copys over the previous
contents of column D and leaves column C alone.

A B C D E F
as ad af ag ah ak
as ad IT ag ah ak

Any ideas on how I could get this to work?

Thanks alot!

-Brian

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,365
Default Copy Paste Macro - Pls Help!

Try this, just requires that the sheet with your data on it be 'selected'
when you run it. Prsumes your data starts in row 1 but you can change that
by changing the value of Const FirstDataRow.

Sub FillTheBlanks()
Const FirstDataRow = 1 ' change if needed
Dim LastDataRow As Long 'last row in C with data in it
Dim LC As Long ' loop counter
LastDataRow = Range("C" & Rows.Count).End(xlUp).Row
If LastDataRow < (FirstDataRow + 1) Then
Exit Sub ' nothing to do
End If
Application.ScreenUpdating = False
For LC = FirstDataRow To LastDataRow
If IsEmpty(Range("A1").Offset(LC, 0)) And _
Not (IsEmpty(Range("A1").Offset(LC, 2))) Then
'copy column A down
Range("A1").Offset(LC, 0) = Range("A1").Offset(LC - 1, 0)
'copy column B down
Range("A1").Offset(LC, 1) = Range("A1").Offset(LC - 1, 1)
'copy column D down
Range("A1").Offset(LC, 3) = Range("A1").Offset(LC - 1, 3)
'copy column E down
Range("A1").Offset(LC, 4) = Range("A1").Offset(LC - 1, 4)
'copy column F down
Range("A1").Offset(LC, 5) = Range("A1").Offset(LC - 1, 5)
End If
Next
Application.ScreenUpdating = False
End Sub

"Bongard" wrote:

Hi I am trying to do a copy paste macro for a spread sheet a data
import that skips over a few fields. The spreadsheet is about 650 rows
so going through it manually is very tedious. I want the macro to be
able to copy paste when column "A" is blank the date from the row above
in columns A,B & D, E, F. It would look like this:

A B C D E F
as ad af ag ah ak
IT LO

After macro is run - seeing that column A is blank it would copy paste
from above to looke like this - Notice it copys over the previous
contents of column D and leaves column C alone.

A B C D E F
as ad af ag ah ak
as ad IT ag ah ak

Any ideas on how I could get this to work?

Thanks alot!

-Brian


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 59
Default Copy Paste Macro - Pls Help!

Awesome I got it to work! That will save me some huge headaches in the
future!

Thanks a lot !
brian


JLatham (removethis) wrote:
Try this, just requires that the sheet with your data on it be 'selected'
when you run it. Prsumes your data starts in row 1 but you can change that
by changing the value of Const FirstDataRow.

Sub FillTheBlanks()
Const FirstDataRow = 1 ' change if needed
Dim LastDataRow As Long 'last row in C with data in it
Dim LC As Long ' loop counter
LastDataRow = Range("C" & Rows.Count).End(xlUp).Row
If LastDataRow < (FirstDataRow + 1) Then
Exit Sub ' nothing to do
End If
Application.ScreenUpdating = False
For LC = FirstDataRow To LastDataRow
If IsEmpty(Range("A1").Offset(LC, 0)) And _
Not (IsEmpty(Range("A1").Offset(LC, 2))) Then
'copy column A down
Range("A1").Offset(LC, 0) = Range("A1").Offset(LC - 1, 0)
'copy column B down
Range("A1").Offset(LC, 1) = Range("A1").Offset(LC - 1, 1)
'copy column D down
Range("A1").Offset(LC, 3) = Range("A1").Offset(LC - 1, 3)
'copy column E down
Range("A1").Offset(LC, 4) = Range("A1").Offset(LC - 1, 4)
'copy column F down
Range("A1").Offset(LC, 5) = Range("A1").Offset(LC - 1, 5)
End If
Next
Application.ScreenUpdating = False
End Sub

"Bongard" wrote:

Hi I am trying to do a copy paste macro for a spread sheet a data
import that skips over a few fields. The spreadsheet is about 650 rows
so going through it manually is very tedious. I want the macro to be
able to copy paste when column "A" is blank the date from the row above
in columns A,B & D, E, F. It would look like this:

A B C D E F
as ad af ag ah ak
IT LO

After macro is run - seeing that column A is blank it would copy paste
from above to looke like this - Notice it copys over the previous
contents of column D and leaves column C alone.

A B C D E F
as ad af ag ah ak
as ad IT ag ah ak

Any ideas on how I could get this to work?

Thanks alot!

-Brian



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 59
Default Copy Paste Macro - Pls Help!

Thanks a lot this will save me some huge headaches in the future!!

-brian

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 multiple worksheets of a workbook, and paste onto a Word document ( either create new doc file or paste onto an existing file.) I need this done by VBA, Excel Macro Steven Excel Programming 1 October 17th 05 08:56 AM
Copy Paste macro GWB Direct Excel Discussion (Misc queries) 2 May 9th 05 03:31 PM
Copy and Paste macro needs to paste to a changing cell reference loulou Excel Programming 0 February 24th 05 10:29 AM
how to count/sum by function/macro to get the number of record to do copy/paste in macro tango Excel Programming 1 October 15th 04 01:16 PM
Macro to Copy/Paste then Paste to Next Line tomkarakowski Excel Programming 1 May 28th 04 01:19 AM


All times are GMT +1. The time now is 11:44 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"