Thank you for your interest but I have worked it out.
Posts by ape
-
-
-
Hi Roy thanks for responding. Below is the workbook code, not sure if it's of any help. There are lots of other sheets but they contain data only. I have also listed the actual code in the list box. I can update the RowSource from any where else whit in the main from e.g. Combo boxes but not from within the list box itself. The list box simply contains list of work sheet names. This RowSource up date should simply display the data in the selected work sheet.
Code
Display MoreSub OpenHeatPumpElecSpec() Dim Frm As Object Unload MainForm Application.ScreenUpdating = True 'Prompt whilst formating sheet Set Frm = PromptForm With Frm .Load .Caption = "" .Show vbModeless .Repaint End With 'Format Variants (required after updting sheet) and data sheets (required after new data has been entered) Call HeatPumpDesign.FormatSheets DoEvents Unload Frm Set Frm = Nothing 'Launch form and initialise variant entries Set Frm = HeatPumpDesign With Frm .Load .Show vbModeless .ListData.Font.Size = 10 .SystemNum.RowSource = "List" .Clearform If Sheets("storage").Range("W9").Value = 0 Then .DialogueBox.Value = "Data base empty" Else .DialogueBox = "System specifications available in data base are displayed in list box below, select system number for electrical requirements" .ListData.RowSource = "DataBase" End If End With Set Frm = Nothing End Sub Actual list box code; Private Sub ListData_Click() 'Set Listbox RowSource <--- "Display selected sheet" Dim Sht As Worksheet Set Sht = Sheets("storage") If ListData.ListIndex = 0 Then GoTo NotValid Sht.Range("x10").Value = ListData.ListIndex With Sht 'Loop through worksheets (ignor named sheets!) to find matching data page number For Each WS In ThisWorkbook.Worksheets Select Case WS.Name Case "Variants", "storage", "Data2", "Help", "Master", "manifold", "Blank" Case Else WS.Unprotect Password:="a3839p" If WS.Cells(1, 6).Value = .Range("x10").Value Then DialogueBox.Value = "System configuration No." & WS.Cells(1, 6).Value & _ " selected. Electrical requirements is displayed in list box below." With Me.ListData .Selected(.ListIndex) = False 'Deselect .RowSource = WS.Cells(1, 7).Value End With SysIndex = WS.Name GoTo Finish End If End Select Next WS End With NotValid: Finish: Set Sht = Nothing End Sub
-
Hi Roy
I have several work sheets each with a name and a unique reference number that are listed in a list box (hence looping). The code should display the sheet contents after the list box RowSource is updated. This routine works fine from other places within the code but not within the list box itself! I have tried to deselect but it not working. The list box is on a form.
Thank you
-
I have a list box with several lines, when I select a row I would like to change the RowSource depending on the value of ListIndex. However the RowSource does not refresh! Here is the code;
Public WS As Worksheet
Public Var1 as Integer
.
.
-
Hello Roy. Thank you for the suggestions, I had tried both options (.Value and .address) but I get a Run-time error. I have attached sample work book at different stages. I think List Box does not allow RowSource refresh whilst line selection is active.
Thanks
-
Sorry sholud read "Name Manager"
-
just tried this;
Me.ListData.RowSource = "'" & Ws.Name & "'!A2:M" & Range("M" & Rows.Count).End(xlUp).Row
no luck!
-
Thanks Roy & Kenneth. The program has many user defined sheets which is set up from selections from user Form ComboBoxes, data will be entered in these sheets and this forms a data base. Once each sheet is defined; a dyamic variable with data range is setup and stored in maned manager. At the start of the the program data base will be listed in the list box. So the user will be able to select an item and the sheet's contents will be shown in the list box. Dynamic range name for each sheet is stored in G1. So changes to code (apart from Case statement, "it was a long day") does not work. Sheet selection using ComboBox works absolutley fine, it is the line selection from the list box which is not working!
Even code Me.ListData.RowSource = "" is not clearing the box!! -
Thank you for your comments. Indeed value of G1 is the new Rowsource which is loaded everytime a sheet is selected. I had tried address option but rowsource does not refresh. This only occures if line selection is made within the list box, if this is done from another control (as in case one) there are no issues!
-
Hi all
I have a list box which displays various information depending on what the rowsource is set to. Currentley I have a combo box which which is used to select the line number and set the rowsource. However what I would like to do is to set the rowsource when specific lines are selected in the listbox itself. I have tried varioud way but nothing seems to update the list! Any help will be appreciate.Here is the code;
This works :-Code
Display MorePublic Sub SystemNum_Change() 'Combobox 'Set Listbox RowSource <--- "Display selected sheet" If Sheets("storage").Range("w9").Value = 0 Then DialogueBox.Value = "Data bank empty" Else 'Loop through worksheets to find the matching sheet number Sheets("storage").Range("x10").Value = SystemNum.Value For Each Ws In ThisWorkbook.Worksheets If Ws.Name = "Variants" Then GoTo NextSheets ElseIf Ws.Name = "storage" Then GoTo NextSheets ElseIf Ws.Name = "Data2" Then GoTo NextSheets ElseIf Ws.Name = "Help" Then GoTo NextSheets ElseIf Ws.Name = "Master" Then GoTo NextSheets ElseIf Ws.Name = "manifold" Then GoTo NextSheets ElseIf Ws.Name = "Blank" Then GoTo NextSheets Else If Ws.Cells(1, 6).Value = Sheets("storage").Range("x10").Value Then 'Match sheet number DialogueBox.Value = "System configuration No." & Ws.Cells(1, 6).Value & " selected. Electrical requirements is displayed in list box below." Me.ListData.RowSource = Ws.Range("G1").Value 'New Rowsource SysIndex = Ws.Name End If End If NextSheets: Next Ws End If End Sub This doesn't:- Public Sub ListData_Click() 'List box Dim ListItemNumber As Integer With Me.ListData For ListItemNumber = 0 To .ListCount - 1 If ListItemNumber > 0 Then If .Selected(ListItemNumber) Then Sheets("storage").Range("x10").Value = ListItemNumber GoTo ItemSelected End If End If Next ListItemNumber End With ItemSelected: For Each Ws In ThisWorkbook.Worksheets If Ws.Name = "Variants" Then GoTo NextSheets ElseIf Ws.Name = "storage" Then GoTo NextSheets ElseIf Ws.Name = "Data2" Then GoTo NextSheets ElseIf Ws.Name = "Help" Then GoTo NextSheets ElseIf Ws.Name = "Master" Then GoTo NextSheets ElseIf Ws.Name = "manifold" Then GoTo NextSheets ElseIf Ws.Name = "Blank" Then GoTo NextSheets Else If Ws.Cells(1, 6).Value = Sheets("storage").Range("X10").Value Then ' Match sheet number DialogueBox.Value = "System configuration No." & Ws.Cells(1, 6).Value & " selected. Electrical requirements is displayed in list box below." Me.ListData.Selected(Sheets("storage").Range("X10").Value) = False ' Deselect Me.ListData.RowSource = vbNullString ' Me.ListData.RowSource = Ws.Range("G1").Value ' New Rowsource 'Or --- Me.ListData.RowSource = "'" & Ws.Name & "'!G1" SysIndex = Ws.Name End If End If NextSheets: Next Ws End Sub
-
Thanks got it sorted!
-
Hi all
I have an excel VBA application where I disable the X button at application launch, when quitting the application the last sheet remains open and I can't close it! The code I use is;Public DisableX As Boolean
Sub Workbook_BeforeClose(Cancel As Boolean)
'Close workbook from main form only!
If DisableX = False Then Cancel = True
End SubAny thoughts will be appreciated.
-
Thanks I finally got round to look at this again. I took a completely different approach! Your link gave a better idea, Thanks
-
runtime error at line ".LeftHeaderPicture = WsMaster.PageSetup.LeftHeaderPicture"
-
Thanks for the reply. I have a code which generates the a new page page further up in the program. Sheet name is then passed on to be filled with logos headings etc. I tried a similar code but I keep getting the error below which I can't get rid of!
"runtime erroe 438 Object doesn't support this property or method"
The picture is in jpeg formatcode;
Private Sub CopyMasterSheet(SheetName As String)
'Update header, footer and cells from page "Master"
Dim WsMaster As Worksheet
Set WsMaster = Sheets("Master")
Set Ws = Sheets(SheetName)
WsMaster.Cells.Copy
Ws.Paste
With Ws.PageSetup
.LeftFooter = WsMaster.PageSetup.LeftFooter
.CenterFooter = WsMaster.PageSetup.CenterFooter
.RightFooter = WsMaster.PageSetup.RightFooter
.CenterHeader = WsMaster.PageSetup.CenterHeader
.LeftHeaderPicture = WsMaster.PageSetup.LeftHeaderPicture
.RightHeader = WsMaster.PageSetup.RightHeader
.FitToPagesWide = 1
.FitToPagesTall = 1
End With
End Sub -
I have a master sheet with some data and shapes both in header and footer. I want to copy the entire sheet to a newly created sheet including shapes(images) that are in the header and footer regions (like for like). Can anyone help?
Thanks in advance. -
I have a master sheet with some data and shapes both in header and footer. I want to copy the entire sheet to a newly created sheet including shapes(images) that are in the header and footer regions (like for like). Can anyone help?
Thanks in advance. -
Great thanks for the code, more efficient way of setting up. For "YES" or "NO" (hide or show sheet) decision I have setup code below which works well.
For Each Ws In ThisWorkbook.Worksheets
.
.
.
For Each CellRange In Ws.Cells.SpecialCells(xlCellTypeAllValidation).Cells
With CellRange
If .Validation.Type = xlValidateList Then
If .Value = .Range("D1:D1").Value Then
Ws.Visible = True
Else
Ws.Visible = False
End If
End If
End With
Next CellRange
.
.
.
Next Ws -
I have validation data " Yes and NO" set up on a sheet. How can I check if selection is "YES" or "NO"? e.g return TRUE if YES, False if NO
Any help will be appreciated.
Thank youCode;
Code
Display MorePrivate Sub NewDataSheet(SheetName As String) Dim Ws As Worksheet .Range("D1").Value = "YES" .Range("E1").Value = "NO" Set Ws = Worksheets(SheetName) With Ws.Range("B1").Validation .Add xlValidateList, xlValidAlertStop, xlBetween, "=$D$1:$E$1" .InCellDropdown = True .InputTitle = True .ShowInput = True End With End Sub