Excel Stack & Queue VBA

nomad815

New Member
Joined
Apr 17, 2005
Messages
2
..........................................................................................................
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Hi

How about
Code:
Sub pop()
Set curSP = Range("D:D").Find(what:="SP")

Range(curSP.Address).Offset(3, 0).Value = "SP"
Range(curSP.Address).ClearContents

Range(Range(curSP.Address).Offset(1, -1), Range(curSP.Address).Offset(3, -1)).ClearContents

End Sub

for the POP code.


Tony
 
Upvote 0
Hi There,

I tested these two procedures and worked OK :

Code:
Dim DinamicRange As Range
Dim EventNr As Long
'Dim J
Dim ItemsArr(1 To 3)
Dim StoredValue() As Variant


Sub Push()
    Set DinamicRange = Range("C2:C22")
    On Error Resume Next
    With DinamicRange
        If .SpecialCells(xlCellTypeBlanks).Count < 3 Then
            MsgBox "Stack Full", vbExclamation
            Exit Sub
        End If
        Do
            Randomize
            EventNr = Int((100 * Rnd) + 1)
            If Int(EventNr / 2) = (EventNr / 2) Then
                J = J + 1
                ItemsArr(J) = EventNr
            End If
        Loop While J < 3
        Set PopulatedCells = .SpecialCells(xlCellTypeConstants)
        If PopulatedCells Is Nothing Then
            .Cells(.Cells.Count) = ItemsArr(1)
            .Cells(.Cells.Count - 1) = ItemsArr(2)
            .Cells(.Cells.Count - 2) = ItemsArr(3)
        Else
            StoredValue = PopulatedCells.Value
            Set PopulatedCells = PopulatedCells.Offset(-3)
            PopulatedCells.Value = StoredValue
            .Cells(.Cells.Count, 1) = ItemsArr(1)
            .Cells(.Cells.Count - 1) = ItemsArr(2)
            .Cells(.Cells.Count - 2) = ItemsArr(3)
        End If
    End With
End Sub


Sub Pop()
    On Error Resume Next
    Set DinamicRange = Range("C2:C22")
    With DinamicRange
        Set PopulatedCells = .SpecialCells(xlCellTypeConstants)
        If PopulatedCells Is Nothing Then
            MsgBox "No more Items to pull !", vbCritical
        Else
            StoredValue = PopulatedCells.Value
            Set PopulatedCells = PopulatedCells.Offset(1).Resize(PopulatedCells.Offset(1).Rows.Count)
            PopulatedCells.Value = StoredValue
            PopulatedCells.Cells(1).Offset(-1).ClearContents
            PopulatedCells.Cells(PopulatedCells.Rows.Count).ClearContents
        End If
    End With
End Sub

Regards.
 
Upvote 0
..........................................................................................................
 
Upvote 0

Forum statistics

Threads
1,224,885
Messages
6,181,588
Members
453,055
Latest member
cope7895

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