Results 1 to 3 of 3

Thread: ??

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2008
    Posts
    7

    ??

    How do i explain..

    I'm running a macro from a sheet to show a form. This form is the basis to put data into that particular sheet. Now when i run the macro the initiliaze from the form is running. I did solved the problem thx to people on this forum to change the caption of the chechbox when the standaard database is filled or not filled. Therefore i go in the initilize to the sheet standaard but afterwards i need to return to the last active sheet. I found a way but i'm not that happy with it. The initiliaze doesn't show the sheet where to put data in.

    For example

    Standaard = database
    Home = navigation sheet to go to other sheets when date is filled
    Sheet 1 = 1ste of the month
    Macro is run from sheet1 --> initialize --> show form --> possibility to put in data

    Now the form shows up but the background is still the home page and i need the active sheet in this example sheet 1 (if date is different then this sheet needs to change also)

    Code:
    Private Sub UserForm_Initialize()
        MultiPage1.Value = 0
        ActiveSheet.Range("d2").Select
        Label10.Caption = ActiveSheet.Range("d2")
        Call algemeen
        Chk1 = False
        ....
    --> initilize calls for sub..

    Code:
    Private Sub algemeen()
    Dim std As Worksheet
        Dim TempName As String
        Set std = Worksheets("standaard")
        std.Visible = xlSheetVisible
        std.Select
        Range("B8:B19").Select
        ActiveCell.Offset(0, 0).Select
        For I = 1 To 12
        TempName = "chk" & I
        If ActiveCell <> "" Then
        ActiveCell.Offset(0, 16).Select
        Me.Controls(TempName).Caption = ActiveCell.Value
        Me.Controls(TempName).Enabled = True
        ActiveCell.Offset(1, -16).Select
        Else
        Me.Controls(TempName).Caption = ""
        Me.Controls(TempName).Enabled = False
        ActiveCell.Offset(1, 0).Select
        End If
        Next
        std.Visible = xlSheetVeryHidden
    1   Worksheets("HOME").Select
    2   ActiveCell.Offset(0, 2).Select
    3   Application.Run ("Datum")
    4   Pause (2)
    End Sub
    --> Application.run ("datum") is the macro to go from the homepage to the sheet according to the date. I tried with a pauze macro but it isn't helping..In this example sheet 1 needs to be displayed in the back of the screen.

    Code:
    Sub Datum()
    '
    ' Ga naar de desbetreffende dag van de maand
    '
        Dim I As Integer
        Sheets("HOME").Select
        Application.ScreenUpdating = False
        Selection.Offset(0, -2).Select
        If ActiveCell.Text = "" Then
        MsgBox ("Je moet op de datum gaan staan")
        Range("a1").Select
        Else
        Dim a As Variant
        a = ActiveCell.Text
        Sheets(a).Visible = True
        Sheets(a).Select
            
            ActiveSheet.Unprotect
        Range("D2:K2").Select
        Selection.Copy
        Range("S6").Select
        Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
            False, Transpose:=False
        Range("D1").Select
        Application.CutCopyMode = False
        Selection.Copy
        Range("S5").Select
        Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
            False, Transpose:=False
        Range("S4").Select
        Application.CutCopyMode = False
        ActiveCell.FormulaR1C1 = "=IF(R[1]C>R[2]C+0.25,""OK"",""NIET OK"")"
        Range("S4:S6").Select
        Range("S6").Activate
        Selection.Font.ColorIndex = 2
        Range("a1").Select
        ActiveSheet.Protect
        
        ActiveWindow.SmallScroll Down:=-150
        End If
    End Sub
    --> This macro i also need in a seperate way to navigate to the daily database sheets.


    Question --> i want to initiliaze (this for the caption of the checkboxes) but then return to the form with the wright background.

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: ??

    if you want a specific sheet visible behind your user form, activate the sheet, if you want it to happen immediately then use do events to allow the change to show before the code continues
    sheets(a).activate
    DoEvents
    'rest of code
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: ??

    Please try to be as descriptive as you can with thread titles.

    ?? really doesn't tell anyone anything about what your question is.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width