Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Copy based on condition in target cell

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,117
Default Copy based on condition in target cell

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 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
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 and Paste based on Condition EJ Excel Discussion (Misc queries) 1 June 27th 07 11:17 PM
Copy range based on condition Sotomayor Excel Programming 1 September 10th 06 01:11 AM
copy cell based on condition where row numbers are not the same. john gibson Excel Programming 1 August 7th 06 02:24 PM
Copy Row based on a condition [email protected] Excel Worksheet Functions 1 April 19th 06 06:05 PM
How to copy only some rows from range based on condition? [email protected][_2_] Excel Programming 2 January 30th 06 01:04 AM


All times are GMT +1. The time now is 12:46 AM.

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"