What am i doing wrong with this code?

kingleviathan

Board Regular
Joined
Aug 23, 2010
Messages
57
Hi Excel Gurus

Would anyone be able to advise what I am doing wrong with my code or a better way of doing it? I greatly appreciate you help :)

i have this code -

range("A" & ?).select
Selection.ListObject.ListRows(?).Delete

I need to use this code as entirerow.delete or similar code will not work

In column AA - starting at cell 1 - i have cells with numbers ie AA1 has 3 AA2 has 5, AA3 has 20

So starting with the laste used cell (ie. in my example it is AA3) - I need 20 inserted into the (?)

The process is then repeated for AA2. So AA2 has 5 inserted into the (?) in my code.

Ditto for AA1

Note: it is very possible that in some cases there may be no entries in AA..
Also - It is unknown what will be the cell used in AA a row count for last cell in AA may be required.

Code:
Sub Test()
 
Dim r as range
Dim LastRow as long
 
Do while ("AA1") <> ""                                                 'if first cell is blank then
          LastRow = Cells(Rows.Count, "AA").End(xlUp).Row  'Find last cell in AA
          set r = cells.value("AA" & LastRow)                      'make r the value of last cell in AA

          range("A" & r).select                                         'Select cell of row to be deleted in A (not AA)                                          
          Selection.ListObject.ListRows(r).Delete                 'Delete that row 
 
          r.delete                                                          'Delete last cell used in AA
 
loop
 
End sub
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Hi Giordana

No it wont do what i need

Your code assumes I know the value of the cell number in column AA. The values in each cell of AA being the row number of duplicates within a linked range from sharepoint. For this reason conventional delete wont work

Therefore the (?) i need to fill needs to be the value of each cell in AA starting with the last used cell in AA first. Followed by the second last used cell in AA
 
Upvote 0

Forum statistics

Threads
1,224,567
Messages
6,179,571
Members
452,927
Latest member
whitfieldcraig

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