Need to have multi-items in list to pass to other macro.

drmingle

Board Regular
Joined
Oct 5, 2009
Messages
229
Objective: To pass multi-selected items to other macro to perform routine.

Known issues: Sometimes I have one item selected sometimes 20, but in all cases I need the name of the item selected to pass to the next routine and execute appropriately.

NOTE: each selected item should be treated seperately.

Code from mutli-list box:

Code:
Private Sub UserForm_Activate()
Dim i As Worksheet
    
    For Each i In ActiveWorkbook.Worksheets
        If i.Name Like "*Pricing[ ]#*" Then
            ListBox1.AddItem i.Name
        End If
    Next i
    
End Sub

Code from command button on multi-list form:

Code:
Private Sub CommandButton1_Click()
Dim text As String
Dim i As Integer
For i = 0 To Me.ListBox1.ListCount - 1
    If Me.ListBox1.Selected(i) Then
        text = text & Me.ListBox1.List(i) & vbNewLine
    End If
Next i
MsgBox "Items you selected: " & vbNewLine & text
GetSelectedItemsText = text
Unload Me
Call Create_SPAsummary
Call Move_SPApricing
Call Copy_Facility
End Sub

Where Items need to pass to (items in red):

Code:
[Sub Copy_Facility()
'
' Copy_Facility: move data from individual selected pricing sheets to summary page
'
'
Application.ScreenUpdating = False
'copy sheet name to summary
    Sheets("[COLOR=#ff0000]ABC Pricing 05-21-2013[/COLOR]").Select
    Range("A1").Select
    Selection.Copy
    Sheets("SPA_Summary").Select
    Range("C5").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Columns("C:C").EntireColumn.AutoFit
    Selection.Font.Bold = True
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlBottom
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
        .MergeCells = False
    End With
    Range("B5").Select
'copy target percentage
    Sheets([COLOR=#ff0000]"ABC Pricing 05-21-2013")[/COLOR].Select
    Range("G3").Select
    Selection.Copy
    Sheets("SPA_Summary").Select
    Range("C6").Select
    Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
        xlNone, SkipBlanks:=False, Transpose:=False
    Sheets("Tulane Unive Pricing 05-21-2013").Select
    Range("G4").Select
    Application.CutCopyMode = False
    Selection.Copy
    Sheets("SPA_Summary").Select
    Range("C7").Select
    Selection.PasteSpecial Paste:=xlPasteFormulasAndNumberFormats, Operation:= _
        xlNone, SkipBlanks:=False, Transpose:=False
    Sheets[COLOR=#ff0000]("ABC Pricing 05-21-2013").[/COLOR]Select
    Range("G5").Select
    Application.CutCopyMode = False
    Selection.Copy
    Sheets("SPA_Summary").Select
    Range("C8").Select
    Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
        xlNone, SkipBlanks:=False, Transpose:=False
    Sheets[COLOR=#ff0000]("ABC Pricing 05-21-2013").Se[/COLOR]lect
    Range("G6").Select
    Application.CutCopyMode = False
    Selection.Copy
    Sheets("SPA_Summary").Select
    Range("C9").Select
    Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
        xlNone, SkipBlanks:=False, Transpose:=False
    Sheets("[COLOR=#ff0000]ABC Pricing 05-21-2013").[/COLOR]Select
    Range("G7").Select
    Application.CutCopyMode = False
    Selection.Copy
    Sheets("SPA_Summary").Select
    Range("C10").Select
    Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
        xlNone, SkipBlanks:=False, Transpose:=False
    Sheets("[COLOR=#ff0000]ABC Pricing 05-21-2013")[/COLOR].Select
    Range("G8").Select
    Application.CutCopyMode = False
    Selection.Copy
    Sheets("SPA_Summary").Select
    Range("C11").Select
    Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
        xlNone, SkipBlanks:=False, Transpose:=False
    Sheets("[COLOR=#ff0000]ABC Pricing 05-21-2013")[/COLOR].Select
    Range("G9").Select
    Application.CutCopyMode = False
    Selection.Copy
    Sheets("SPA_Summary").Select
    Range("C12").Select
    Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
        xlNone, SkipBlanks:=False, Transpose:=False
    Columns("C:C").Select
    Application.CutCopyMode = False
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlBottom
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
        .MergeCells = False
    End With
    Range("C5").Select
    Selection.Font.Bold = True
    Selection.Borders(xlDiagonalDown).LineStyle = xlNone
    Selection.Borders(xlDiagonalUp).LineStyle = xlNone
    Selection.Borders(xlEdgeLeft).LineStyle = xlNone
    Selection.Borders(xlEdgeTop).LineStyle = xlNone
    With Selection.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    Selection.Borders(xlEdgeRight).LineStyle = xlNone
    Selection.Borders(xlInsideVertical).LineStyle = xlNone
    Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
    Range("B4").Select
Application.ScreenUpdating = True
End Sub
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.

Forum statistics

Threads
1,215,474
Messages
6,125,025
Members
449,204
Latest member
LKN2GO

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