copy data based on highlighted cell in column into lastrow from sheet to another

Abdo

Board Regular
Joined
May 16, 2022
Messages
228
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
Hi

I have about 3000 rows some cells in column C contain highlighted cell , what I want macro to search from last row contains highlighted cell until last row doesn't contain color in cell for column C and should delete color in cell when copy to sheet2 .
in sheet2 should clear data from row2 when I run the macro every time to replace data

the data in Sheet1

cell.xlsm
ABC
1DATEACCOUNT REFBALANCES
201/05/2023PUR PURCHASE INV 000011120,000.00
302/05/2023PUR PURCHASE INV 000011210,000.00
403/05/2023PUR PURCHASE INV 00001131,200.00
504/05/2023PUR PURCHASE INV 00001141,300.00
605/05/2023PUR PURCHASE INV 00001151,000.00
706/05/2023PUR PURCHASE INV 00001161,200.00
807/05/2023PUR PURCHASE INV 00001171,200.00
908/05/2023PUR PURCHASE INV 0000118100.00
1009/05/2023PA PAYING 791300.00
1110/05/2023PA PAYING 792400.00
1211/05/2023PA PAYING 793500.00
1312/05/2023PA PAYING 794340.00
1413/05/2023PUR PURCHASE INV 00001191,200.00
1514/05/2023PUR PURCHASE INV 00001201,000.00
1615/05/2023PUR PURCHASE INV 0000121100.00
1716/05/2023PUR PURCHASE INV 00001221,200.00
1817/05/2023PUR PURCHASE INV 00001231,200.00
Sheet1


result in sheet2

cell.xlsm
ABC
1DATEACCOUNT REFBALANCES
212/05/2023PA PAYING 794340.00
313/05/2023PUR PURCHASE INV 00001191,200.00
414/05/2023PUR PURCHASE INV 00001201,000.00
515/05/2023PUR PURCHASE INV 0000121100.00
616/05/2023PUR PURCHASE INV 00001221,200.00
717/05/2023PUR PURCHASE INV 00001231,200.00
Sheet2
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
The macro considers that you have the standard color yellow and that it is not conditional formatting.
The format on Sheet2 must have the corresponding one, column A the date and column C the amount.

Try this:
VBA Code:
Sub Copy_data_based_on_highlighted_cell()
  Dim sh1 As Worksheet
  Dim f As Range
 
  Set sh1 = Sheets("Sheet1")
 
  With Application
    .ScreenUpdating = False
    .FindFormat.Clear
    .FindFormat.Interior.Color = 65535
 
    Sheets("Sheet2").Rows("2:" & Rows.Count).ClearContents
    Set f = sh1.Range("C:C").Find("*", sh1.Range("C" & Rows.Count), xlValues, xlPart, xlByRows, xlPrevious, False, SearchFormat:=True)
    If Not f Is Nothing Then
      sh1.Range(f, sh1.Range("A" & Rows.Count).End(3)).Copy
      Sheets("Sheet2").Range("A2").PasteSpecial xlPasteValues
    End If
 
    .CutCopyMode = False
    .FindFormat.Clear
    .ScreenUpdating = True
  End With
End Sub

--------------
Let me know the result and I'll get back to you as soon as I can.
Cordially
Dante Amor
--------------​
 
Last edited:
Upvote 1
Solution

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

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