0

I have 2 sheets and 1 macros that pastes values from one to another. The macros is working. I copied it and changed it a bit. But it can't run -

'run time error 9'

which is visibility issue.

All sheets are in same excel file.

original macros code, it works:

Sub original()

For j = 18 To 28
        Worksheets("Express_vnzp").Select
        srok = Cells(26, j).Value
        stav = Cells(31, j).Value
        komis = Cells(28, j).Value
        stavka_privlech = Cells(29, j).Value

        For i = 10 To 12

            PD = Cells(i, 17).Value
            Worksheets("Ðàñ÷åòû").Select
            Cells(3, 2).Value = stav
            Cells(4, 2).Value = srok
            Cells(5, 2).Value = komis
            Cells(7, 2).Value = stavka_privlech
            Cells(15, 2).Value = PD
            marzha2 = Cells(23, 2).Value

            Worksheets("Express_vnzp").Select
            Cells(i, j).Value = marzha2

        Next
Next
End Sub

I copied and changed i,j - not working.

Sub erj()

    For j = 3 To 4
            Worksheets("creditcard").Select
            srok = Cells(26, j).Value
            stav = Cells(31, j).Value
            komis = Cells(28, j).Value
            stavka_privlech = Cells(29, j).Value

            For i = 5 To 6

                PD = Cells(i, 17).Value
                Worksheets("ras").Select
                Cells(3, 2).Value = stav
                Cells(4, 2).Value = srok
                Cells(5, 2).Value = komis
                Cells(7, 2).Value = stavka_privlech
                Cells(15, 2).Value = PD
                marzha2 = Cells(23, 2).Value

                Worksheets("creditcard").Select
                Cells(i, j).Value = marzha2

            Next
    Next
    End Sub

gives 'runtime error', its visibility issue.

braX
  • 11,506
  • 5
  • 20
  • 33
ERJAN
  • 23,696
  • 23
  • 72
  • 146
  • 3
    In which line do you get the error? Please read [How to avoid using Select in Excel VBA](https://stackoverflow.com/questions/10714251/how-to-avoid-using-select-in-excel-vba) and apply this technique to your code and update it in your question if it doesn't already fix your issue. Also I recommend to use `Option Explicit` and declare all your variables properly. – Pᴇʜ Feb 21 '20 at 10:04
  • 2
    Do you have a car? Take it to the workshop and say "It's not working". After the mechanic opens the bonnet, starts the engine, goes around the block, and tells you it's OK, you tell him that you mean the windscreen wipers. Try it. They'll love you. – Variatus Feb 21 '20 at 10:37
  • 1
    @Variatus Actually he told which error it is. So it is probably more like he has a garage full of cars and tells the mechanic that a car has error number 9, but doesn't tell which car :) They'll love him anyway :) – Pᴇʜ Feb 21 '20 at 10:43
  • 1
    You haven't just changed `i` and `j` though. @Variatus - :) I want SO to add a shortcut for that, I can see a lot of use for it. – SJR Feb 21 '20 at 10:47
  • @Pᴇʜ - Worksheets("creditcard").Select is where the error shows – ERJAN Feb 21 '20 at 11:15
  • found the bug - it did not see the sheet because there was SPACE at the end – ERJAN Feb 21 '20 at 11:22
  • @ERJAN as alreay said in the first comment. Using `.Select` is a very unreliable method and has to be avoided at any cost. Also it makes your code super slow. – Pᴇʜ Feb 21 '20 at 12:07

0 Answers0