Last piece of the puzzle!

Bengo

Board Regular
Joined
Apr 14, 2010
Messages
210
Good afternoon,

I have written the following code:

Sub NewPO()

'Cleardown unused PO numbers

Range("e" & Rows.Count).End(xlUp).Offset(1, 0).Select

Selection.EntireRow.ClearContents


'Generate new PO number based on last number in coloumn "i"

Range("P4").Value = "GG" & Range("I" & Rows.Count).End(xlUp).Value + 1 & Range("P2").Value

'Copy New PO into Relevant PO box

Range("J" & Rows.Count).End(xlUp).Offset(1, 0).Value = "GG" & Range("I" & Rows.Count).End(xlUp).Value + 1 & Range("P2").Value


'Copy last number into last cell of column "i"

Range("i" & Rows.Count).End(xlUp).Offset(1, 0).Value = Range("I" & Rows.Count).End(xlUp).Value + 1


End Sub


I am having issues with the first section (in Bold). What I am trying to do is find the last populated cell in column E, drop down one cell, and clear the contents in the row. For some reason it doesn't clear any text in the relevant cells in that row?

Can anyone see why?

Many thanks
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
  1. You don't need to select cells to perform actions on them (although this wouldn't explain the problem you're facing). Try this:

Code:
Dim LastRow As Long
LastRow = Cells(Rows.Count, 5).End(xlUp).Offset(1).Row
Rows(LastRow).ClearContents
 
Last edited:
Upvote 0
Thanks

No that doesn't work either. My last populated row is A15 to L15

I have text written in I16 & J16. When I run this, I'd expect it to find the cell E15, drop to row 16, and clear contents. However it doesn't....
 
Upvote 0
Are you sure there's nothing else in column E after row 15? Try running this:

Code:
Msgbox "Last row in column E is " & cells(rows.Count,5).end(xlup).row
 
Upvote 0
Sorry I've figured it out! I'm being daft. The remain text in the cells in column I and J are what the rest of my Macro are asking it to input. So effectively the whole row is deleted and the rest is then entered

Can you think of a way of selecting all rows below the last populated cell in column E, not just the single one below?

many thanks
 
Upvote 0
Was thinking something like this, but I can't get it to work...

Dim LastRow As Long
LastRow = Cells(Rows.Count, 5).End(xlUp).Offset(1).Row
Rows(LastRow).Select
Selection.End(xlDown).ClearContents

thanks
 
Upvote 0
Ok this worked, although you could probably simplify this compared to mine:

Dim LastRow As Long
LastRow = Cells(Rows.Count, 5).End(xlUp).Offset(1).Row
Rows(LastRow).Select
Rows(ActiveCell.Row & ":" & Rows.Count).ClearContents

Thanks very much for your help, much appreciated!
 
Upvote 0
You can get rid of the select & do this
Code:
lastrow = Cells(Rows.Count, 5).End(xlUp).Offset(1).Row
Rows(lastrow & ":" & Rows.Count).ClearContents
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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