problem with Updating alll of the values of a listcolumn

mahhdy

Board Regular
Joined
Sep 15, 2016
Messages
86
Hi,
I want to update values of ID row of my list box by adding 1 to them. But VBA shows me error. Can anyone help?

Code:
Sub id_update()
    
    Dim mn As ListColumns
    Set mn = Worksheets("ShipReceive").ListObjects("tbl").ListColumns(1).DataBodyRange
        For Each Cell In mn
            Cell.Value = Cell.Value + 1
        Next
End Sub
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Your mn variable is of type ListColumns, but DataBodyRange is of type Range.
 
Upvote 0
Your mn variable is of type ListColumns, but DataBodyRange is of type Range.
You are absolutely right, I Already figured it out, But the procedure takes a long time to run. Is there any lighter/ faster way to do so?
in my list there are about 5000 rows of data.
Tnx
 
Upvote 0
1. Insert 1 into some cell outside ListBox.
2. Ctrl+C
3. Select desired range.
4. Go to Paste Special and select Values (in Paste section) and Add (in Operation section)
5. Press OK.
 
Upvote 0
I think you know that I am working on a procedure, and in VBA mode.
I was working on that too.
Now I am trying to send the number to the clipboard and then paste special it.
Yours,
M

1. Insert 1 into some cell outside ListBox.
2. Ctrl+C
3. Select desired range.
4. Go to Paste Special and select Values (in Paste section) and Add (in Operation section)
5. Press OK.
 
Upvote 0
Code:
' Insert 1 somewhere (in this case - AA1 cell).
Range("AA1").Value=1
Range("AA1").Copy
' Add one to each cell in DataBodyRange
Worksheets("ShipReceive").ListObjects("tbl").ListColumns(1).DataBodyRange.PasteSpecial xlPasteValues, xlPasteSpecialOperationAdd
 
Upvote 0

Forum statistics

Threads
1,214,817
Messages
6,121,720
Members
449,050
Latest member
MiguekHeka

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