PC Review


Reply
Thread Tools Rate Thread

Copy Paste Macro - Pls Help!

 
 
Bongard
Guest
Posts: n/a
 
      10th Oct 2006
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

 
Reply With Quote
 
 
 
 
=?Utf-8?B?SkxhdGhhbQ==?=
Guest
Posts: n/a
 
      10th Oct 2006
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
>
>

 
Reply With Quote
 
Bongard
Guest
Posts: n/a
 
      11th Oct 2006
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
> >
> >


 
Reply With Quote
 
Bongard
Guest
Posts: n/a
 
      11th Oct 2006
Thanks a lot this will save me some huge headaches in the future!!

-brian

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to copy and paste values (columns)I have a macro file built C02C04 Microsoft Excel Programming 2 2nd May 2008 01:51 PM
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 Microsoft Excel Programming 1 17th Oct 2005 08:56 AM
Copy and Paste macro needs to paste to a changing cell reference =?Utf-8?B?bG91bG91?= Microsoft Excel Programming 0 24th Feb 2005 10:29 AM
how to count/sum by function/macro to get the number of record to do copy/paste in macro tango Microsoft Excel Programming 1 15th Oct 2004 01:16 PM
Macro to Copy/Paste then Paste to Next Line tomkarakowski Microsoft Excel Programming 1 28th May 2004 01:19 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:39 AM.