Results 1 to 4 of 4

Thread: how to reference a specific worksheet on vba code

  1. #1
    Junior Member
    Join Date
    Sep 2013
    Posts
    7
    Rep Power
    0

    how to reference a specific worksheet on vba code

    hi all,

    I have a problem with regards to worksheet referencing. I have a workbook with 3 sheets. Sheet 1 and 2 contain the data while sheet 3 contains the command button that calls a userform.
    in sheet 3 there are the active & vacant button for sheet 1 and 2 that when clicked will call a userform. in the userform there is a combobox that will contain the value based on sheet 1 and 2. if the sheet1 active button is clicked the userform combobox will display the active channels based on sheet1, same with sheet 1 vacant channel.. sheet2 vacant and active button will do the same from sheet 2.

    My problem is i cannot reference the commandbutton code to the right sheet. it only works when the active/vacant commanduttons is located in sheet 1 and sheet2 but when they are located in sheet 3 and sheet 1 and 2 are hidden, it does not work.

    I attached a copy of my workbook for your reference.

    Regards,
    rydysh
    Attached Files Attached Files

  2. #2
    Junior Member
    Join Date
    Sep 2013
    Posts
    7
    Rep Power
    0
    i tried this one but it didnt work, something is wrong with my referencing..

    Private Sub UserForm_Initialize()
    Dim r As Long
    Dim ws As Worksheet
    Set ws = Worksheets("sheet1")
    With ws
    For r = 2 To Range("C" & Rows.Count).End(xlUp).Row
    If Range("D" & r).Value = "ACTIVE" Then
    ComboBox1.AddItem Range("C" & r).Value
    End If
    Next r
    End With
    End Sub

  3. #3
    Moderator
    Join Date
    Jul 2012
    Posts
    156
    Rep Power
    13
    One possibility.
    Attached Files Attached Files

  4. #4
    Junior Member
    Join Date
    Sep 2013
    Posts
    7
    Rep Power
    0
    thanks bakerman..it works

Similar Threads

  1. Replies: 2
    Last Post: 08-23-2013, 01:11 PM
  2. Add VBA Reference From Another Application Excel To PowerPoint
    By ds1001 in forum Rajan Verma's Corner
    Replies: 1
    Last Post: 06-02-2013, 02:43 PM
  3. Replies: 7
    Last Post: 05-17-2013, 10:38 PM
  4. VBA Code to Generate Events at Specific frequency
    By ChiswickBridge in forum Excel Help
    Replies: 0
    Last Post: 02-11-2013, 08:20 AM
  5. Delete Names In A Specific Worksheet
    By Admin in forum Excel and VBA Tips and Tricks
    Replies: 0
    Last Post: 08-14-2011, 02:38 AM

Posting Permissions

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