Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi,
I have written a visual basic script that uses Excel to store 'recipe' data. The user is able to see currently stored recipes in a combo box. I've recently been asked to sort the recipes so that they appear in the combo box in alphabetical order. This is where I'm having problems and I wondered whether anyone reading this can point me in the right direction? This is my script, when the form is initiated I'm getting a "Run-time error 1004: Method 'range of object '_Global' failed. Private Sub UserForm_Initialize() Dim intNextRow As Integer Dim strRowID As String Dim strMixID As String Dim LastRow As String Dim WriteRow As String Dim WriteRange As String 'On Error Resume Next intNextRow = 4 Set ExcelAppRecipe = GetObject(, "excel.application") ' Set Reference to currently open Excel Application ExcelAppRecipe.Application.Sheets("Recipe").Activa te LastRow = ExcelAppRecipe.Selection.SpecialCells(11).Row WriteRow = "" & "5" & ":" & LastRow & "" WriteRange = "" & "A" & LastRow & "" ExcelAppRecipe.Rows(WriteRow).Select ExcelAppRecipe.Range(WriteRange).Activate ExcelAppRecipe.Selection.Sort Key1:=Range("B5"), Order1:=xlAscending strRowID = "Recipe!B" & intNextRow strMixID = ExcelAppRecipe.Range(strRowID).Value Do While strMixID < "" cboSelectMix.AddItem strMixID intNextRow = intNextRow + 1 strRowID = "Recipe!B" & intNextRow strMixID = ExcelAppRecipe.Range(strRowID).Value Loop Set ExcelAppRecipe = Nothing End Sub I'm pretty sure it has something to do with the line ExcelAppRecipe.Selection.Sort Key1:=Range("B5"), Order1:=xlAscending but I'm not sute what I've done wrong? If I look on the excel sheet it has selected the correct area but hasn't sorted it. Any ideas? Thanks in advance |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
programming command bars | Excel Discussion (Misc queries) | |||
Counting, command button and programming in VB | Excel Discussion (Misc queries) | |||
Programming a "Save as..." command button within Excel | Excel Discussion (Misc queries) | |||
Sort command does not sort some columns? | New Users to Excel | |||
Programming command button to execute on a different worksheet | Excel Programming |