VBA ignoring last row

JoeRooney

Board Regular
Joined
Nov 27, 2017
Messages
169
Office Version
  1. 365
Hi,

I have the below code which joins cells from B:BW with a "," delimiter for each row, it is working perfect except it skips the last row.

There is data in column B in the last row so I cant figure out why it would skip it.

Would anyone have any idea why it skips it?

VBA Code:
Dim i As Long
Dim LastRow As Long
LastRow = Range("B" & Rows.Count).End(xlUp).Row

    Columns("A:A").Select
    Application.CutCopyMode = False
    Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
    Rows("1:1").Select
    Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
    Range("A1").Select
    ActiveCell.FormulaR1C1 = "TOM Policy"

    For i = 2 To LastRow
        Range("A" & i).Formula = Join(Application.Index(Range("B" & i & ":BW" & i).Value, 1, 0), ",")
    Next i
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
You need to assign a value to LastRow after inserting the row, not before inserting.
 
Upvote 0
You might want to try this alternative code :
VBA Code:
Dim i As Long, LastRow As Long
Columns(1).Insert
Rows(1).Insert
Range("A1") = "TOM Policy"
Range("A2:A" & Cells(Rows.Count, "C").End(xlUp).Row).Formula = _
    Join(Application.Index(Range("B2:BW2").Value, 1, 0), ",")
 
Upvote 0

Forum statistics

Threads
1,214,975
Messages
6,122,538
Members
449,088
Latest member
RandomExceller01

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