Urgent..TRICKY..How to find last entries of each row "Having different ranges"

Gauraog

New Member
Joined
Jan 11, 2014
Messages
12
Hi All, Im a begainer to VBA.

I like to to find a last 3 entries of each row .

eg. I have a Row A2:N2 which contains data.....similarly I have a data in cell A3toG3........A4:Z4...and so on till the last row which has data.

Data will be always start from Column A but not fixed where will it be ending. (Actually it will keep changing)

Basically each row will have data but its not fixed in which column it will be ending.

I want to copy last 3 entries of each row which has data. Can someone please give me a VBA code to perform this activity. Quick response much appreciated.
 
Wow...its working......Thank you Rick and Thank you so much Mark......much appreciated.

No, it probably is NOT working correctly as I omitted something very important that Mark pointed out to me in Message #18. Stop using what I posted earlier, this is the code you should be using...

Rich (BB code):
Sub GetLastThreeValuesPerRow()
  Dim R As Long, C As Long, LastRow As Long, Counter As Long
  Dim Values As Variant, ArrIn As Variant, ArrOut As Variant, WS As Worksheet
  For Each WS In Worksheets
    LastRow = WS.Cells(Rows.Count, "A").End(xlUp).Row
    ArrIn = WS.Range("A1", WS.Cells(LastRow, "O"))
    ReDim ArrOut(1 To UBound(ArrIn), 1 To 3)
    For R = 1 To UBound(ArrIn)
      Counter = 3
      For C = 15 To 1 Step -1  '15 is the column number for Column O
        If Counter = 0 Then Exit For
        If Len(ArrIn(R, C)) Then
          ArrOut(R, Counter) = ArrIn(R, C)
          Counter = Counter - 1
        End If
      Next
    Next
    WS.Range("P1").Resize(UBound(ArrOut), 3) = ArrOut
  Next
End Sub
 
Upvote 0

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)

Forum statistics

Threads
1,217,364
Messages
6,136,117
Members
449,993
Latest member
Sphere2215

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