Need Help with UserForm VBA Coding

amowatt

New Member
Joined
Dec 11, 2014
Messages
2
I am working in Excel 2013.

I am trying to create an UserForm for my department for formatting reports that we create that don't come out "Pretty"

I have a few text boxes for things like freezing the sheet on XX, print titles, naming sheets, etc etc

At the bottom of the user form, I have a list box that displays the sheets in the workbook, so that the user can select which sheets they want to format with this tool.

The trouble I am having is;

I think I need to make each of the worksheets selected in the listbox into variables, so that the text boxes know which sheets to apply the desired format to.

I don't have much code at the moment, only the code that is displaying the items in the list box, and the coding for closing the userform.

I need help getting to the next stage of my project.

Let me know if I can clear up what I'm trying to do, or what I need, because this is very wordy and probably not that clear.

Thanks in advance,
Alex
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
This is code, that while needs modifying, is very similar to what you're attempting to do. However, instead of highlighting, which I do, you'll be changing the " ''For loop to highlight selected rows" area to be the "apply the desired format" area.

Code:
    '''Determine how many rows are selected------------
    iListCount = 0
    For iList = lbPopulate.ListCount - 1 To 1 Step -1
        If lbPopulate.Selected(iList) = True Then
            iListCount = iListCount + 1
        End If
    Next iList
    '''End----------------------------------------------

    '''Resize array-------------------------------------
    ReDim aListInput(iListCount)
    '''End----------------------------------------------

    '''Create array to hold selected categories---------
    For iList = lbPopulate.ListCount - 1 To 1 Step -1
        If lbPopulate.Selected(iList) = True Then
            aListInput(iListCount) = lbPopulate.List(iList)
            iListCount = iListCount - 1
        Else
        End If
    Next iList
    '''End----------------------------------------------
    
    '''Determine how many rows are selected------------
    For iList = lbPopulate.ListCount - 1 To 1 Step -1
        If lbPopulate.Selected(iList) = True Then
            iListCount = iListCount + 1
        End If
    Next iList
    '''End----------------------------------------------
    
    '''For Loop to highlight selected rows--------------
    For iList = iListCount To 1 Step -1
    Do
        iSelectRow = iSelectRow + 1
    Loop Until wsPopulate.Cells(iSelectRow, 1) = aListInput(iList)
    wsPopulate.Range(Cells(iSelectRow, 1), Cells(iSelectRow, 2)).Interior.Color = 65535
    Next iList
    Exit Sub
    '''End----------------------------------------------

Once you look it over, feel free to re-post if there's more help you need. Good luck.
 
Upvote 0
Hey, thanks a bunch, I'll take a good look at it when I have the time, I appreciate the help thus far!
 
Upvote 0

Forum statistics

Threads
1,216,095
Messages
6,128,795
Members
449,468
Latest member
AGreen17

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