ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Copy based on condition in target cell (https://www.excelbanter.com/excel-programming/382346-copy-based-condition-target-cell.html)

JWaniek

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


Susan

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





All times are GMT +1. The time now is 03:41 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com