Přidat otázku mezi oblíbenéZasílat nové odpovědi e-mailemVyřešeno prosba excel visual basic

Ahoj, mam nasledujici makro ve visual basicu ktery mi hazi chybu " run time error 91 object variable or with block variable not set" na radku PosledniBunka = Cells(PosledniRadek, PosledniSloupec)

makro je nasledujici, jeho funkce je aby ohranicil tlustym ohranicenim oblast od bunky B3 az po bunku, kterou zjistim pomoci PosledniRadek a Posledni sloupec, ale nejak se mi ji nedari ulozit do PosledniBunka....


Sub radeksloupec()

Sheets("Report").Select

Dim PosledniBunka As Range

PosledniRadek = Cells(Rows.Count, 4).End(xlUp).Row
PosledniSloupec = Cells(3, Columns.Count).End(xlToLeft).Column

PosledniBunka = Cells(PosledniRadek, PosledniSloupec)

    Range("B3:PosledniBunka").Select
    Selection.Borders(xlDiagonalDown).LineStyle = xlNone
    Selection.Borders(xlDiagonalUp).LineStyle = xlNone
    With Selection.Borders(xlEdgeLeft)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlMedium
    End With
    With Selection.Borders(xlEdgeTop)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlMedium
    End With
    With Selection.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlMedium
    End With
    With Selection.Borders(xlEdgeRight)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlMedium
    End With

End Sub

předem děkuji za pomoc

Řešení:

Sub radeksloupec()

Dim PosledniBunka As Range
Dim PosledniRadek As Long
Dim PosledniSloupec As Integer

With Worksheets("Report")

    PosledniRadek = .Cells(Rows.Count, 4).End(xlUp).Row
    PosledniSloupec = .Cells(3, Columns.Count).End(xlToLeft).Column
    
    Set PosledniBunka = .Cells(PosledniRadek, PosledniSloupec)
    
    With .Range("B3:" & PosledniBunka.Address & "")
        .Borders(xlDiagonalDown).LineStyle = xlNone
        .Borders(xlDiagonalUp).LineStyle = xlNone
        With .Borders(xlEdgeLeft)
            .LineStyle = xlContinuous
            .ColorIndex = 0
            .TintAndShade = 0
            .Weight = xlMedium
        End With
        With .Borders(xlEdgeTop)
            .LineStyle = xlContinuous
            .ColorIndex = 0
            .TintAndShade = 0
            .Weight = xlMedium
        End With
        With .Borders(xlEdgeBottom)
            .LineStyle = xlContinuous
            .ColorIndex = 0
            .TintAndShade = 0
            .Weight = xlMedium
        End With
        With .Borders(xlEdgeRight)
            .LineStyle = xlContinuous
            .ColorIndex = 0
            .TintAndShade = 0
            .Weight = xlMedium
        End With
    End With
End With
End Sub
Jsou zobrazeny jen nové odpovědi. Zobrazit všechny
Předmět Autor Datum
Set PosledniBunka = Cells(PosledniRadek, PosledniSloupec)
Siki83 19.04.2021 15:22
Siki83
oki, ted mi to ale haze error 1004 method range od object_global failed pro radek Range("B3:Posledni…
Tomasino 19.04.2021 15:25
Tomasino
Sub radeksloupec() Dim PosledniBunka As Range Dim PosledniRadek As Long Dim PosledniSloupec As Integ…
Siki83 19.04.2021 15:43
Siki83
děkuji :-)
Tomasino 19.04.2021 15:47
Tomasino
Nebo přes resize Sub radeksloupec() Dim PosledniRadek As Long Dim PosledniSloupec As Integer With W… poslední
Siki83 19.04.2021 15:51
Siki83
Sub radeksloupec()

Dim PosledniBunka As Range
Dim PosledniRadek As Long
Dim PosledniSloupec As Integer

With Worksheets("Report")

    PosledniRadek = .Cells(Rows.Count, 4).End(xlUp).Row
    PosledniSloupec = .Cells(3, Columns.Count).End(xlToLeft).Column
    
    Set PosledniBunka = .Cells(PosledniRadek, PosledniSloupec)
    
    With .Range("B3:" & PosledniBunka.Address & "")
        .Borders(xlDiagonalDown).LineStyle = xlNone
        .Borders(xlDiagonalUp).LineStyle = xlNone
        With .Borders(xlEdgeLeft)
            .LineStyle = xlContinuous
            .ColorIndex = 0
            .TintAndShade = 0
            .Weight = xlMedium
        End With
        With .Borders(xlEdgeTop)
            .LineStyle = xlContinuous
            .ColorIndex = 0
            .TintAndShade = 0
            .Weight = xlMedium
        End With
        With .Borders(xlEdgeBottom)
            .LineStyle = xlContinuous
            .ColorIndex = 0
            .TintAndShade = 0
            .Weight = xlMedium
        End With
        With .Borders(xlEdgeRight)
            .LineStyle = xlContinuous
            .ColorIndex = 0
            .TintAndShade = 0
            .Weight = xlMedium
        End With
    End With
End With
End Sub

Nebo přes resize

Sub radeksloupec()

Dim PosledniRadek As Long
Dim PosledniSloupec As Integer

With Worksheets("Report")

    PosledniRadek = .Cells(Rows.Count, 4).End(xlUp).Row
    PosledniSloupec = .Cells(3, Columns.Count).End(xlToLeft).Column
   
    With .Range("B3").Resize(PosledniRadek - 2, PosledniSloupec - 1)
        .Borders(xlDiagonalDown).LineStyle = xlNone
        .Borders(xlDiagonalUp).LineStyle = xlNone
        With .Borders(xlEdgeLeft)
            .LineStyle = xlContinuous
            .ColorIndex = 0
            .TintAndShade = 0
            .Weight = xlMedium
        End With
        With .Borders(xlEdgeTop)
            .LineStyle = xlContinuous
            .ColorIndex = 0
            .TintAndShade = 0
            .Weight = xlMedium
        End With
        With .Borders(xlEdgeBottom)
            .LineStyle = xlContinuous
            .ColorIndex = 0
            .TintAndShade = 0
            .Weight = xlMedium
        End With
        With .Borders(xlEdgeRight)
            .LineStyle = xlContinuous
            .ColorIndex = 0
            .TintAndShade = 0
            .Weight = xlMedium
        End With
    End With
End With
End Sub

Zpět do poradny Odpovědět na původní otázku Nahoru