empty cell copy paste macro

Tonyk1051

Board Regular
Joined
Feb 1, 2021
Messages
132
Office Version
  1. 2019
Platform
  1. Windows
wasnt sure how to go about this but i need a macro for the instructions below

in column k if a cell has the word "out" and the cell in column O
is empty then change the current word in column M to unresolved

once the above rules have been executed then

any cells that are empty in column O copy the data from column N paste it in the corresponding empty cell in column O
and high light It yellow

FYI the amount of lines differ every day anywhere from 45k to 700k (sheet name is Page1)
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Looping through 45k-700k rows might not be fast, so you may want to look into using arrays, but this should work.
VBA Code:
Sub tonyk()
Dim i As Long, lastrow As Long
lastrow = Range("K" & Rows.Count).End(xlUp).Row

For i = 2 To lastrow
    If Cells(i, 11).Value = "out" And Cells(i, 15).Value = "" Then Cells(i, 13).Value = "Unresolved"
Next i

With Range("O2:O" & lastrow).SpecialCells(xlCellTypeBlanks)
    .FormulaR1C1 = "=RC[-1]"
    .Interior.Color = 65535
End With
End Sub
 
Upvote 0
It tooks 27s for 1 milion rows of data
Does it annoy too much?
VBA Code:
Option Explicit
Sub test()
Dim lr As Long, i As Long, k As Long, rng, arr(1 To 1048576, 1 To 1)
Dim t
t = Timer
lr = Cells(Rows.Count, "K").End(xlUp).Row
rng = Range("K1:P" & lr).Value
For i = 1 To lr
    If rng(i, 5) = "" Then
        If rng(i, 1) = "out" Then rng(i, 3) = "unresolved"
        rng(i, 5) = rng(i, 4)
        k = k + 1
        arr(k, 1) = "O" & i
    End If
Next
Range("K1:P" & lr).Value = rng
For i = 1 To k
    Range(arr(i, 1)).Interior.Color = vbYellow
Next
MsgBox Timer - t
End Sub
 
Upvote 0
Solution
It tooks 27s for 1 milion rows of data
Does it annoy too much?
VBA Code:
Option Explicit
Sub test()
Dim lr As Long, i As Long, k As Long, rng, arr(1 To 1048576, 1 To 1)
Dim t
t = Timer
lr = Cells(Rows.Count, "K").End(xlUp).Row
rng = Range("K1:P" & lr).Value
For i = 1 To lr
    If rng(i, 5) = "" Then
        If rng(i, 1) = "out" Then rng(i, 3) = "unresolved"
        rng(i, 5) = rng(i, 4)
        k = k + 1
        arr(k, 1) = "O" & i
    End If
Next
Range("K1:P" & lr).Value = rng
For i = 1 To k
    Range(arr(i, 1)).Interior.Color = vbYellow
Next
MsgBox Timer - t
End Sub
thanks bebo works perfect
 
Upvote 0

Forum statistics

Threads
1,214,919
Messages
6,122,260
Members
449,075
Latest member
staticfluids

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top