+ Reply to Thread
Results 1 to 9 of 9

Thread: Focus cells

  1. #1
    Forum Contributor
    Join Date
    04-21-2009
    Location
    Canada
    MS-Off Ver
    Excel 2003
    Posts
    111

    Focus cells

    Hi Friends,

    Below code is for an userform. Data gets filled in Sheet1.But Sheet1 is in "Veryhidden mode" for my requirement. So, the range A4 in sheet1 is focussed according to below code.There is Sheet2 which is directly linked with Sheet1. (only Sheet2 is visible inscreen)
    All I need is ,The range A4 should be focussed in sheet2. and data should always go into sheet1 in very hidden mode.


    Private Sub cmdSUBMIT_CLICK()
    ActiveWorkbook.Sheets("Sheet1").Activate
        If cboName.Value = "MICHEL" Then
        Range("A4").Show
        Range("A4").Select
        ElseIf cboName.Value = "ANDY" Then
        Range("A101").Show
        Range("A101").Select
    End if

    Hope the explanation is clear. Any help please. Thanks in advance
    Last edited by sivdin; 05-17-2011 at 10:10 AM.

  2. #2
    Forum Guru Domski's Avatar
    Join Date
    12-14-2009
    MS-Off Ver
    What does it matter?
    Posts
    3,933

    Re: Focus cells

    Hi,

    You can't activate or select cells on a very hidden worksheet. In fact in general when writing VBA code you should avoid doing so in the vast majority of cases. What do you want to do with A4/A101?

    Dom
    "May the fleas of a thousand camels infest the crotch of the person who screws up your day and may their arms be too short to scratch..."

    Use code tags when posting your VBA code: [code] Your code here [/code]

    Remember, saying thanks only takes a second or two. Click the little star to give some Rep if you think an answer deserves it.

  3. #3
    Valued Forum Contributor
    Join Date
    04-11-2011
    Location
    Cincinnati, Ohio
    MS-Off Ver
    Excel 2007
    Posts
    262

    Re: Focus cells

    Where do you assign the data at?
    Focus in on sheet2 but put the data on sheet1. (If you are allowed to do this. I think you can.)
    You said they are linked, with formulas I guess, so putting data in sheet2 should update sheet1.

  4. #4
    Forum Contributor
    Join Date
    04-21-2009
    Location
    Canada
    MS-Off Ver
    Excel 2003
    Posts
    111

    Re: Focus cells

    Hi, I need the selection of cells in visible sheet only.(sheet2)

  5. #5
    Forum Contributor
    Join Date
    04-21-2009
    Location
    Canada
    MS-Off Ver
    Excel 2003
    Posts
    111

    Re: Focus cells

    Data is in Sheet1.Sheet2 is linked by formulas(=)
    I need cells to focus in Sheet2.
    Sheet1 always stays invisible.
    According to posted code, the cell focus will be in sheet1 only.

  6. #6
    Valued Forum Contributor
    Join Date
    04-11-2011
    Location
    Cincinnati, Ohio
    MS-Off Ver
    Excel 2007
    Posts
    262

    Re: Focus cells

    So instead of activating sheet1 activate sheet2?

    Example code.

    Sub cmd_Submit_Click()
    'Focus Sheet1.
    Worksheets("Sheet1").Activate
    
    'Now focus Sheet2.
    Worksheets("Sheet2").Activate
    
    'If check box names entered value is equal to DATA_1
        If cboName.Value = "DATA_1" Then 'do the following
        'Range("A4").Show
        'Select Range A4.
        Range("A4").Select
        'Else if check box names value is equal to DATA_2
        ElseIf cboName.Value = "DATA_2" Then 'do the following
        'Range("A101").Show
        'Select Range A101.
        Range("A101").Select
    End if
    
    'Insert the forms text box value into that sheet.
    Selection.Value = "DATA_3"

  7. #7
    Forum Contributor
    Join Date
    04-21-2009
    Location
    Canada
    MS-Off Ver
    Excel 2003
    Posts
    111

    Re: Focus cells

    Hi, Thanks for the code,
    But, whether that this code fills the data in sheet1 or sheet2.
    I require the dat to be filled in sheet1, after that cell focus should be in sheet2

  8. #8
    Forum Guru Domski's Avatar
    Join Date
    12-14-2009
    MS-Off Ver
    What does it matter?
    Posts
    3,933

    Re: Focus cells

    As I said you can't select or activate a very hidden workbook. You didn't answer my question as to what you wanted to do but I'm guessing this might help...

    Private Sub cmdSUBMIT_CLICK()
    With Sheets("Sheet1")
        If cboName.Value = "MICHEL" Then
            .Range("A4").Value = "Something"
        ElseIf cboName.Value = "ANDY" Then
            .Range("A101").Value = "Something else"
        End If
    End With
    End If

    Dom
    "May the fleas of a thousand camels infest the crotch of the person who screws up your day and may their arms be too short to scratch..."

    Use code tags when posting your VBA code: [code] Your code here [/code]

    Remember, saying thanks only takes a second or two. Click the little star to give some Rep if you think an answer deserves it.

  9. #9
    Forum Contributor
    Join Date
    04-21-2009
    Location
    Canada
    MS-Off Ver
    Excel 2003
    Posts
    111

    Re: Focus cells

    Thanks Domski. I understood now...

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.2.0