does workbook contain worksheet

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am creating a series of userforms that
1) checks if the open workbook contains a specific worksheet.
2) Loads a textbox in the form with data from a cell
3) allows the text to be added to
4) Re-loads the modified text to the cell
5) Saves the worksheet

I am having trouble getting the sheet verification and the textbox to load
the cell text. Any ideas?
 
'-----------------------------------------------------------------
Function SheetExists(Sh As String, _
Optional wb As Workbook) As Boolean
'-----------------------------------------------------------------
Dim oWs As Worksheet
If wb Is Nothing Then Set wb = ActiveWorkbook
On Error Resume Next
SheetExists = CBool(Not wb.Worksheets(Sh) Is Nothing)
On Error GoTo 0
End Function
 
Thank you Bob. I got the first part to work. Now for the second part,
Getting the TextBox to show the cell data.

Everytime a workbook is open (that contains the Sheet), I get an "Out of
Subscript" error.

Private Sub UserForm_Initialize()
Dim MRange As Range

Sheets("Eo-Cover").Activate
Set MRange = ActiveSheet.Range("B24")
TMAffectText = MRange.Value
End Sub
 
maybe...

Private Sub UserForm_Initialize()
if sheetexist("eo-cover",thisworkbook) then
tmaffecttext.text = Sheets("Eo-Cover").Range("B24").value
else
tMAffectText.text = "missing sheet"
end if
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top