Insert Copied Cells every time a value shows

KiloHotel

New Member
Joined
Feb 4, 2018
Messages
42
Office Version
  1. 2016
Platform
  1. Windows
  2. MacOS
Hi guys,

Is there a VBA code that someone can help me with, What I am trying to achieve is insert a row of copied cells to another row that has a value of "here"

A4 is the row I want to copy.

So along Column B each cell has the formula ;

=IF(C5=C4,"","HERE")

And the value returns as HERE at random rows and it is quite a lengthy process to copy and paste 1000's of rows of data, I am certain there is a VBA wizard on here that has a simple solution.

And of course if anything else needs clarifying, Just ask away.

Thanks in advance!
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Hi KiloHotel,

please test the codes on copies of your original data and see if it comes near to what you want to do, both codes will work on the ActiveSheet in Excel:

VBA Code:
Sub MrE1612515_ValuesRow4()
'https://www.mrexcel.com/board/threads/insert-copied-cells-every-time-a-value-shows.1219751/
Dim lngMax As Long
Dim lngcounter As Long

With ActiveSheet
  lngMax = WorksheetFunction.Max(.Range("B" & .Rows.Count).End(xlUp).Row, .Range("C" & .Rows.Count).End(xlUp).Row)
  For lngcounter = 5 To lngMax
    If UCase(.Cells(lngcounter, "B").Value) = "HERE" Then
      .Rows(lngcounter).Value = .Rows(4).Value
    End If
  Next lngcounter
End With
End Sub

VBA Code:
Sub MrE1612515_FormulasRow4()
'https://www.mrexcel.com/board/threads/insert-copied-cells-every-time-a-value-shows.1219751/
Dim lngMax As Long
Dim lngcounter As Long
Dim lngCalc As Long

lngCalc = Application.Calculation
Application.Calculation = xlCalculationManual
With ActiveSheet
  lngMax = WorksheetFunction.Max(.Range("B" & .Rows.Count).End(xlUp).Row, .Range("C" & .Rows.Count).End(xlUp).Row)
  For lngcounter = 5 To lngMax
    If UCase(.Cells(lngcounter, "B").Value) = "HERE" Then
      .Rows(4).Copy .Rows(lngcounter)
    End If
  Next lngcounter
End With
Application.Calculation = lngCalc
End Sub

Ciao,
Holger
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,200
Members
453,022
Latest member
RobertV1609

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