delete a row.

R

RobcPettit

Hi, if Ive assigned values from a1:a20 in vba to 'myarray', and I want
to delete the first row/value so value 2 now becomes 1 etc, what is the
best way to do this.
Regards Robert
 
C

Chip Pearson

Use code like

Rows(1).Delete
or
Dim MyRange As Range
Set MyRange = Range("MyRange")
Range("MyRange")(1, 1).EntireRow.Delete


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
R

RobcPettit

Sorry, didnt word that very well, I meant delete the row in the array
itself.
Regards Robert
 
G

Guest

Sub ABC()
Dim myarray As Variant
myarray = Range("MyRange").Value
' convert to a 1D array
myarray = _
Application.Transpose(myarray)
For i = LBound(myarray) To UBound(myarray) - 1
myarray(i) = myarray(i + 1)
Next
ReDim Preserve myarray(1 To UBound(myarray) - 1)
For i = LBound(myarray) To UBound(myarray)
Debug.Print i, myarray(i)
Next
End Sub
 
G

Guest

Sub ABC()
Dim myarray As Variant
myarray = Range("MyRange").Value
' convert to a 1D array
myarray = _
Application.Transpose(myarray)
For i = LBound(myarray) To UBound(myarray) - 1
myarray(i) = myarray(i + 1)
Next
ReDim Preserve myarray(1 To UBound(myarray) - 1)
For i = LBound(myarray) To UBound(myarray)
Debug.Print i, myarray(i)
Next
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top