RowIndex count match only with visible rows

  • Hello guys,


    I made filtered ComboBox, which is done by using SpecialCells(xlCellTypeVisible), but now I have a problem with data paste. RowIndex, which I use for this, count all rows, not just the filtered rows. Is there a way, how to do something like this:
    RowIndex.SpecialCells(xlCellTypeVisible) = Me.ComboBox1.ListIndex ?


    Here is the code, which I need to "repair"


    Any help you can offer would be hugely appreciated.


  • Re: RowIndex count match only with visible rows


    What is the sheet name of the sheet used for the combo box list?


    Which sheet column in that sheet is used to populate your combo box list?


    Are the values in that column unique?

    We now have a reputation system in place. If my reply helped please "Like" the reply by clicking the "Like" icon at bottom right of my reply.

  • Re: RowIndex count match only with visible rows


    What is the sheet name of the sheet used for the combo box list?
    "Položky"


    Which sheet column in that sheet is used to populate your combo box list?
    Column A and B


    Are the values in that column unique?
    In the column, which is used to populate my combo box list, yes.

  • Re: RowIndex count match only with visible rows


    Your combo box list is a combination of the values in columns A and B? If so, what is the delimiter, if any, between the 2 values?


    Can you give an example of an Item in the combo box list, or better still attach your workbook.


    [sw]*[/sw]

    We now have a reputation system in place. If my reply helped please "Like" the reply by clicking the "Like" icon at bottom right of my reply.

  • Re: RowIndex count match only with visible rows


    The combination is made in this way:

    Code
    Dim cbRange As Range
        Dim LR As Long
        LR = Range("A" & Rows.Count).End(xlUp).Row
        Me.ComboBox3.Clear
        With ComboBox3
            For Each cbRange In Range("A6:A" & LR).SpecialCells(xlCellTypeVisible)
              .AddItem cbRange.Value
              .List(.ListCount - 1, 1) = cbRange.Offset(0, 1)
            Next cbRange
        End With


    I attach a sample workbook, something is in Czech, but I think, that it is OK to understand the code without any problem.


    I know, that my code is a mess in this moment, but I want to "clean it" later (or try to clean it) :D
    forum.ozgrid.com/index.php?attachment/73621/

  • Re: RowIndex count match only with visible rows


    Try changing

    Code
    RowIndex = Me.ComboBox3.ListIndex + 6


    to

    Code
    RowIndex = Application.Match(ComboBox3, Sheets("Položky").UsedRange.Columns(1), 0)


    For each of the 3 command button codes, changing the Combox referenced as appropriate.

    We now have a reputation system in place. If my reply helped please "Like" the reply by clicking the "Like" icon at bottom right of my reply.

  • Re: RowIndex count match only with visible rows


    I tried to do this, but I got an error on this line:

    Code
    UserForm1.txtLabel.Text = .Cells(RowIndex, 1)
  • Re: RowIndex count match only with visible rows


    Because of the way Excel handles Czech script between a worksheet and the VBA script I cannot actually get the user form to show unless I do a load of temporary changes to the VBA script, and I do not have time for that now.


    Looking closer I see that the 3 combo boxes are multi-column, try this

    Code
    RowIndex = Application.Match(ComboBox3.Value, Sheets("Položky").UsedRange.Columns(1), 0)


    if that still gives an error try one of the following

    Code
    RowIndex = Application.Match(ComboBox3.Column(1), Sheets("Položky").UsedRange.Columns(1), 0)


    or possibly

    Code
    RowIndex = Application.Match(ComboBox3.Column(0), Sheets("Položky").UsedRange.Columns(1), 0)


    The combo box column index (0 or 1) depends on the locale settings for Czech Windows and Office.


    If still no luck try removing the UsedRange (including the preceding dot) which will reference the whole of column A to find a match.

    We now have a reputation system in place. If my reply helped please "Like" the reply by clicking the "Like" icon at bottom right of my reply.

  • Re: RowIndex count match only with visible rows


    I tried to do every combination, which you wrote, but still error.


    With the first two variants I got the error again on this line:

    Code
    UserForm1.txtLabel.Text = .Cells(RowIndex, 1)


    With the second two variants I got the error on the changed line:

    Code
    RowIndex = Application.Match(ComboBox1.Column(0), Sheets("Položky").Columns(0), 0


    I found out, that the first column is in Czech Office "0" too, because the second column is "1".


    Do you have any other ideas? :/

  • Re: RowIndex count match only with visible rows


    What is the error you get?


    Can you put the values in the 2 columns of ComboBox3 list here.

    We now have a reputation system in place. If my reply helped please "Like" the reply by clicking the "Like" icon at bottom right of my reply.

  • Re: RowIndex count match only with visible rows


    The error is in German:
    Original:
    Laufzeitfehler "1004":
    Anwendungs - oder objektdefinierter Fehler
    In english:
    Run-time error "1004":
    Application - or object - defined error


    I don't know, what exactly you want from me about the ComboBox3. Can you, please, be more specific?

  • Re: RowIndex count match only with visible rows


    After you show the user form and click the arrow on ComboBox3 let me know a few of the options that show, like this:


    Combobox 1st. column Combobox 2nd. column
    Example 1 Example 1
    Example 2 Example 2
    Example 3 Example 3

    We now have a reputation system in place. If my reply helped please "Like" the reply by clicking the "Like" icon at bottom right of my reply.

  • Re: RowIndex count match only with visible rows


    I just noticed you changed the code options I gave in Post#8 wrongly


    You changed to

    Code
    RowIndex = Application.Match(ComboBox1.Column(0), Sheets("Položky").Columns(0), 0


    it should be

    Code
    RowIndex = Application.Match(ComboBox1.Column(0), Sheets("Položky").Columns(1), 0


    You changed both the combo box column index AND the sheet column index to 0, a sheet cannot have a column index of 0 (index 1 is column A).


    That would cause Run-time Error 1004.


    Try correcting that change and see if you still get the error.

    We now have a reputation system in place. If my reply helped please "Like" the reply by clicking the "Like" icon at bottom right of my reply.

  • Re: RowIndex count match only with visible rows


    Here it is:
    1 Drátek
    2 Kabel
    3 Pravítko


    The main column is the 1st column, the 2nd. column is just an "addition".


    I tried every option with the columns (1 or 0), but now I'm getting another error:
    Run-Time error "13"

  • Re: RowIndex count match only with visible rows


    That is just as I thought it would be.


    The code I gave takes the first column value of the selected item in the combo box then matches that value woth the values in Column A of the sheet and Makes the variable "RowIndex" the row of the matching value.


    Try this

    Code
    RowIndex = Application.Match(CInt(ComboBox1.Column(0)), Sheets("Položky").Columns(1), 0

    We now have a reputation system in place. If my reply helped please "Like" the reply by clicking the "Like" icon at bottom right of my reply.

  • Re: RowIndex count match only with visible rows


    I just noticed, when I got this error and hover over the row with RowIndex...The section "ComboBox1.Column(0)" gives the right number, which was chosen. The "RowIndex =" show me "Error 2042.

  • Re: RowIndex count match only with visible rows


    Our posts crossed, see my reply in Post#15.


    The combo box could be returning the value as a text string, that code change will convert it to a number, then the matching should work.

    We now have a reputation system in place. If my reply helped please "Like" the reply by clicking the "Like" icon at bottom right of my reply.

  • Re: RowIndex count match only with visible rows


    Now it is working, perfect!


    Thank you very much for your help!


    Just a small question..
    I put a date value to the list (from userform), where I have a conditional formatting, but the condition is not used for the value. I need to manually rewrite the date and then the conditional formatting is used.


    I mean the column G.


    Do you know a reason of this problem?

  • Re: RowIndex count match only with visible rows


    You're welcome. Pleased we got there in the end!


    As for the date try changing

    Code
    Sheets("Položky").Cells(RowIndex, 7).Value = .txtBorrowToDate1.Value


    to

    Code
    Sheets("Položky").Cells(RowIndex, 7).Value = CDate(.txtBorrowToDate1.Value)


    Also format the whole of that Table column as Date. (just the Table column "Vypůjčeno do" not the whole sheet column G)

    We now have a reputation system in place. If my reply helped please "Like" the reply by clicking the "Like" icon at bottom right of my reply.

  • Re: RowIndex count match only with visible rows


    Thank you again, that's it.


    Finally everything works.


    I can't do this without your help.


    Thank you very much again and have a nice day!

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!