PC Review


Reply
Thread Tools Rate Thread

Copy based on condition in target cell

 
 
JWaniek
Guest
Posts: n/a
 
      31st Jan 2007
I am not a VBA or Excel macro specialist, which is why I cannot come up
with a solution to this problem on my own.

I have a spreadsheet with several thousand rows. Column G has a bunch of
empty cells. I want to go down row by row and copy the contents of the cell
in column F into the cell next to it in column G if the cell in column G is
empty and then change the text color of the cell in column G to blue.
Something like:
If Gx is empty
copy Fx to Gx
color Gx blue

The above is easy to record in a macro for one cell, but how do I write a
macro that goes down all 3,000 rows and executes this?

Any help would be greatly appreciated.

Jesko Waniek

 
Reply With Quote
 
 
 
 
Susan
Guest
Posts: n/a
 
      1st Feb 2007
Sub waniek()

Dim MyLastRow As Long
Dim MyRange As Range
Dim StartRow As Long
Dim MyRow As Long
Dim rDest As Range
Dim i As Long

MyLastRow = Cells(40000, 7).End(xlUp).Row

Set MyRange = Range("a1:k" & MyLastRow)

i = 1

Do While i < MyLastRow
If Range("g" & i) = "" Then
Set rDest = Range("g" & i)
MyRow = i
Range("f" & MyRow).Copy Destination:=rDest
rDest.Font.ColorIndex = 5
End If
i = i + 1
Loop


End Sub


On Jan 31, 6:11 pm, JWaniek <p...@bellsouth.netnospam> wrote:
> I am not a VBA or Excel macro specialist, which is why I cannot come up
> with a solution to this problem on my own.
>
> I have a spreadsheet with several thousand rows. Column G has a bunch of
> empty cells. I want to go down row by row and copy the contents of the cell
> in column F into the cell next to it in column G if the cell in column G is
> empty and then change the text color of the cell in column G to blue.
> Something like:
> If Gx is empty
> copy Fx to Gx
> color Gx blue
>
> The above is easy to record in a macro for one cell, but how do I write a
> macro that goes down all 3,000 rows and executes this?
>
> Any help would be greatly appreciated.
>
> Jesko Waniek



 
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
Copy and Paste based on Condition =?Utf-8?B?RUo=?= Microsoft Excel Misc 1 27th Jun 2007 11:17 PM
Target cell coloured based on whether one cell has a greater value =?Utf-8?B?S2llcmFubw==?= Microsoft Excel Worksheet Functions 2 12th Oct 2006 10:29 AM
Copy range based on condition =?Utf-8?B?U290b21heW9y?= Microsoft Excel Programming 1 10th Sep 2006 01:11 AM
copy cell based on condition where row numbers are not the same. john gibson Microsoft Excel Programming 1 7th Aug 2006 02:24 PM
Copy Row based on a condition dennis.davis@gmail.com Microsoft Excel Worksheet Functions 1 19th Apr 2006 06:05 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:13 AM.