VBA tweak needed not correctly copying formulas

ItalianPlatinum

Well-known Member
Joined
Mar 23, 2017
Messages
793
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hello,
Hoping someone could assist me on existing code that I have that should be copying data down but it is currently going too far up even though I define the range to start at row 3. So it is overriding my headers on row 2. Anyone able to see anything visibly wrong, I cannot and it is becoming annoying.

VBA Code:
 Dim lr As Long, lr1 As Long
'formatting and formulas for recon sheet
With WsNXF
lr1 = .Cells(rows.count, "A").End(xlUp).row
    .Range("A:B").RemoveDuplicates Columns:=Array(1, 2), Header:=xlYes
    .Range("A:C").HorizontalAlignment = xlCenter
    .Range("C2:T2") = Array("Concatentate A/C", "Prior BD", "Shares", "Income", "P", "B", "LT", "P", "B", "ST", "P", "B", "GAIN", "P", "B", "Total", "P", "B")
    .Range("F1:O1") = Array("", "", "", "LT", "", "", "ST", "", "", "GAIN")
    .Range("C3:C" & lr1).Formula = "=$A3&B3"
    .Range("C3:C" & lr1).Value = .Range("C3:C" & lr1).Value
    .Range("D3:D" & lr1).Formula = "=iferror(VLOOKUP(C3,'Trend_NX'!$C$11:$E$10000,3,FALSE),"""")"
    .Range("E3:E" & lr1).Formula = "=iferror(VLOOKUP(C3,'Trend'!$C$11:$F$10000,4,FALSE),"""")"
    .Range("F3:F" & lr1).Formula = "=SUMIF('ACC'!$C$10:$C$10000,$A3,'FOF ACCRUAL'!$G$10:$G$10000)"
   'ADDITIONAL CODE to column T similar as above

Before Code
1675185417509.png


After Code
1675185185435.png
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
lr1 = .Cells(rows.count, "A").End(xlUp).row

That will result in to an answer of 2

So your ranges are going from for example D3:D2 which is the same as D2:D3.
 
Upvote 0
even though i define C3:C & LR1 it doesn't quite matter? is my option to subtract one from the row count? i want to copy formulas for everything in A ignoring the header on row 2
 
Upvote 0
Try it like
VBA Code:
lr1 = .Cells(rows.count, "A").End(xlUp).row
    if lr1 < 3 Then lr1 = 3
    .Range("A:B").RemoveDuplicates Columns:=Array(1, 2), Header:=xlYes
 
Upvote 0

Forum statistics

Threads
1,214,987
Messages
6,122,613
Members
449,090
Latest member
vivek chauhan

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