VBA to add Line where theres data in the Previous row

menor59

Well-known Member
Joined
Oct 3, 2008
Messages
574
Office Version
  1. 2021
Platform
  1. Windows
Hello Team,

This code works Fine

VBA Code:
  Dim myR As Range
 
  Set myR = Range("C10")
  If Not Intersect(Target, myR) Is Nothing Then
    Application.EnableEvents = False
    Range("F4:Y4" & Range("F" & Rows.Count).End(xlUp).Row).Offset(0).Clear
    On Error Resume Next
    If myR.Value >= 1 Then Range("F3:Y3").Copy Destination:=Range("F3:Y3").Resize(myR.Value)
    On Error GoTo 0
    Application.EnableEvents = True
  End If

it basically takes the Value of C10 example: 3 and copies whats in F3:Y3

but if that value changes to 5 It clears it and uses the data from F3:Y3

put that value below the range if theres data in the previous rows

There will Be data in F3:Y3 so from the first empty cell from Column F Copy F3:Y3 into the Empty First Cell in Column F but Clear Contents from Empty Cell range F:O

Kinda Like this:

C10 = 3
3.jpg


C10 = 5

5.jpg


Even Adding Rows based on C10 is fine...but it shouldnt delete the previous data from that range. There are some formulas in F:Y that needs to stay..

I hope this makes sense.
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.

Forum statistics

Threads
1,215,321
Messages
6,124,239
Members
449,149
Latest member
mwdbActuary

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