Supportnet Computer
Planet of Tech

Supportnet / Forum / Tabellenkalkulation

VBA Endspalte bzw. Endzeile





Frage

Hi Leute! Kann mir vielleicht jemand erklären wie ich per VBA die Endspalte bzw. Endzeile bestimmen kann, sprich die erste Spalte bzw. Zeile in der kein Wert mehr steht. Danke im Voraus Gruß AF

Antwort 1 von Hajo_Zi

Hallo Namensloser,

Option Explicit

Sub Namensloser()
MsgBox "letzte Zeile " & Sheets(1).UsedRange.SpecialCells(xlCellTypeLastCell).Row
MsgBox "Letzte Spalte " & Sheets(1).UsedRange.SpecialCells(xlCellTypeLastCell).Column
End Sub

Gruß Hajo

Antwort 2 von VBA_Anfänger

Danke funktioniert perfekt.

Kannst du mir vielleicht sagen wie ich, dass in folgenden Makro integrieren kann?

Public Sub wert()

Dim i As Long
Dim e As Integer
Dim n As Long

Dim d As String
Dim names As String
Dim tabelle1 As String

tabelle1 = Cells(3, 1).Value



ActiveWorkbook.Sheets(tabelle1).Activate
e = ActiveSheet.Cells(6, 1).Value


i = ComboBox1.Value
a = 1

For b = 1 To e Step 1

j = ActiveSheet.Cells(b, a).Value

If i = j Then
ActiveSheet.Cells(b, a).Select

Exit For
End If

Next b

t1 = DTPicker1.Value
t2 = DTPicker2.Value

ActiveSheet.Range("B10:IV10").Clear

For z = 3 To 60 Step 1

t = ActiveSheet.Cells(10, z).Value
tt = (t1 - t2)

If t = "" Then


ActiveSheet.Cells(10, 2).Select
ActiveSheet.Cells(10, 2) = t1

t3 = tt + 2

Exit For

End If


Next z

For t4 = 3 To t3 Step 1


If t4 <> t3 Then

t1 = t1 - 1
ActiveSheet.Cells(10, t4).Select
ActiveSheet.Cells(10, t4) = t1


End If
´Exit For


Next t4

t4 = t4 - 1

ActiveSheet.Cells(10, t4).Select
ActiveSheet.Cells(10, t4) = t2


´t4 = endspalte

s = Charts.Count

For s = s To 50

If Charts.Count = 0 Then
Exit For
End If

Application.DisplayAlerts = False
Charts(s).Delete
Application.DisplayAlerts = True

Next s

d = ActiveSheet.Cells(8, 1).Value

ActiveSheet.Cells(1, b).Select
n = ActiveSheet.Cells(b, 1).Value
names = n



Charts.Add
ActiveChart.ChartType = xlLine
ActiveChart.SetSourceData Source:=Sheets(tabelle1).Range("B" & b & ":" & d & b), _
PlotBy:=xlRows
ActiveChart.SeriesCollection(1).XValues = Sheets(tabelle1).Range("B10:" & d & "10")
ActiveChart.SeriesCollection(1).Name = names
ActiveChart.Location Where:=xlLocationAsNewSheet
With ActiveChart
.HasAxis(xlCategory, xlPrimary) = True
.HasAxis(xlValue, xlPrimary) = True
End With
With ActiveChart.Axes(xlCategory)
.HasMajorGridlines = False
.HasMinorGridlines = False
End With
With ActiveChart.Axes(xlValue)
.HasMajorGridlines = False
.HasMinorGridlines = False
End With
ActiveChart.HasLegend = False
With Selection.Font
.Name = "Arial"
.Size = 10
End With


m = Charts.Count
Charts(m).Select
Charts(m).Name = names
Sheets(names).Move after:=Sheets(tabelle1)

ActiveWorkbook.Sheets(tabelle1).Select
ActiveSheet.Cells(1, 1).Select

End Sub


Private Sub Ausführen_Click()
Call wert

End Sub

Musste bis jetzt immer in A6 die Endzeile eingeben und in A8 die Endspalte.

Danke im Voraus

Gruß AF

Antwort 3 von Hajo_Zi

Hallo Namensloser,

ein Code mit Kommentaren ist immer Klasse.
A8 wäre für mich keine Endspalte.
Ich habe mal paar Kommentare in den Code geschrieben. Bezeichne beim nächsten ma die Stelle genauer wo was eingetragen werden soll.

Public Sub wert()
Dim i As Long
Dim e As Integer
Dim n As Long
Dim d As String
Dim names As String
Dim tabelle1 As String
´ Ergänzung
Dim Found As Range
´ ****
tabelle1 = Cells(3, 1).Value
With ActiveWorkbook.Sheets(tabelle1)
e = ActiveSheet.Cells(6, 1).Value
i = ComboBox1.Value
a = 1
´ finden des Inhaltes von ComboBox1 im Bereich von Zeile 1 bis Zeile e in Spalte A
´ wozu wird das gesucht ???
Set Found = .Range(.Cells(1, 1), .Cells(e, 1)).Find(i, .Range("A1"), , xlPart, , xlNext)
´ *****
If Found Is Nothing Then Exit Sub ´falls nicht gefunden wird sub verlassen
´ For b = 1 To e
´ j = ActiveSheet.Cells(b, a).Value
´ If i = j Then
´ ActiveSheet.Cells(b, a).Select
´ Exit For
´ End If
´ Next b
t1 = DTPicker1.Value
t2 = DTPicker2.Value
.Range("B10:IV10").Clear
For z = 3 To 60
t = .Cells(10, z).Value
tt = (t1 - t2)
If t = "" Then
.Cells(10, 2).Select
.Cells(10, 2) = t1
t3 = tt + 2
Exit For
End If
Next z
For t4 = 3 To t3
If t4 <> t3 Then
t1 = t1 - 1
´ auf select kann in VBA zu 99% verzichtet werden
´ wozu wird diese Zelle selektiert
.Cells(10, t4).Select
.Cells(10, t4) = t1
End If
´Exit For
Next t4
t4 = t4 - 1
´ auf select kann in VBA zu 99% verzichtet werden
´ wozu wird diese Zelle selektiert
.Cells(10, t4).Select
.Cells(10, t4) = t2
´t4 = endspalte
s = Charts.Count
For s = s To 50
If Charts.Count = 0 Then Exit For
Application.DisplayAlerts = False
Charts(s).Delete
Application.DisplayAlerts = True
Next s
d = .Cells(8, 1).Value
´ auf select kann in VBA zu 99% verzichtet werden
´ wozu wird diese Zelle selektiert
.Cells(1, b).Select
n = .Cells(b, 1).Value
names = n
Charts.Add
ActiveChart.ChartType = xlLine
ActiveChart.SetSourceData Source:=Sheets(tabelle1).Range("B" & b & ":" & d & b), _
PlotBy:=xlRows
ActiveChart.SeriesCollection(1).XValues = Sheets(tabelle1).Range("B10:" & d & "10")
ActiveChart.SeriesCollection(1).Name = names
ActiveChart.Location Where:=xlLocationAsNewSheet
With ActiveChart
.HasAxis(xlCategory, xlPrimary) = True
.HasAxis(xlValue, xlPrimary) = True
End With
With ActiveChart.Axes(xlCategory)
.HasMajorGridlines = False
.HasMinorGridlines = False
End With
With ActiveChart.Axes(xlValue)
.HasMajorGridlines = False
.HasMinorGridlines = False
End With
ActiveChart.HasLegend = False
With Selection.Font
.Name = "Arial"
.Size = 10
End With
m = Charts.Count
´ diese Zeile braucht wohl nicht zu sein
´ dem Ding kannst Du auch einen Namen geben ohne select
Charts(m).Select
Charts(m).Name = names
Sheets(names).Move after:=Sheets(tabelle1)
End With
´ die nachfolgenden Zellen müssen nicht sein
´ da ohne select gearbeitet werden kann
´ ich baue das Beispiel aber nicht nach
ActiveWorkbook.Sheets(tabelle1).Select
ActiveSheet.Cells(1, 1).Select
End Sub

Gruß Hajo

Antwort 4 von VBA_Anfänger

Danke für die schnelle Antwort.

Hintergrund der ganzen Sache ist, dass in A11 bis im moment A87 Kontonummern stehen und in den Spalten daneben der jeweilige Kontostand an dem dementsprechenden Tag. Der neue Kontostand wird jeweils in Spalte B aus einer anderen Tabelle eingefügt. Mit der Auswahl der Kto aus der Combobox und Klick auf Button ausführen wird eine Grafik über den Verlauf der Kontostände generiert.

P.S Das Ding soll von der Zeilen und Spalten Größe nicht begrenzt sein.

Gruß AF

Antwort 5 von VBA_Anfänger

Danke habe das ganze folgendermaßen gelöst.

Public Sub wert()

Dim i As Long
Dim e As Integer
Dim n As Long

Dim d As String
Dim names As String
Dim tabelle1 As String

tabelle1 = Cells(3, 1).Value



ActiveWorkbook.Sheets(tabelle1).Activate
For e = 11 To 200 Step 1

If Cells(e, 1) = Empty Then

Exit For

End If

Next e

´e = ActiveSheet.Cells(6, 1).Value
e = e - 1


´ComboBox1.Value = Empty

i = ComboBox1.Value
a = 1

For b = 11 To e Step 1

j = ActiveSheet.Cells(b, a).Value

If i = j Then
ActiveSheet.Cells(b, a).Select

Exit For
End If

Next b

t1 = DTPicker1.Value
t2 = DTPicker2.Value

ActiveSheet.Range("B10:IV10").Clear

For z = 3 To 60 Step 1

t = ActiveSheet.Cells(10, z).Value
tt = (t1 - t2)

If t = "" Then


ActiveSheet.Cells(10, 2).Select
ActiveSheet.Cells(10, 2) = t1

t3 = tt + 2

Exit For

End If


Next z

For t4 = 3 To t3 Step 1


If t4 <> t3 Then

t1 = t1 - 1
ActiveSheet.Cells(10, t4).Select
ActiveSheet.Cells(10, t4) = t1


End If
´Exit For


Next t4

t4 = t4 - 1

ActiveSheet.Cells(10, t4).Select
ActiveSheet.Cells(10, t4) = t2


For sp = 2 To 255 Step 1

If Cells(10, sp) = Empty Then
Exit For
End If

Next sp

adr = Cells(10, sp).Address

If sp > 26 Then
adr = Mid(adr, 2, 2)
Else
adr = Mid(adr, 2, 1)
End If

ActiveSheet.Range(adr & "10:IV" & e).Clear


´sp = endspalte

s = Charts.Count

For s = s To 50

If Charts.Count = 0 Then
Exit For
End If

Application.DisplayAlerts = False
Charts(s).Delete
Application.DisplayAlerts = True

Next s

d = adr

ActiveSheet.Cells(b, 1).Select
n = ActiveSheet.Cells(b, 1).Value
names = n



Charts.Add
ActiveChart.ChartType = xlLine
ActiveChart.SetSourceData Source:=Sheets(tabelle1).Range("B" & b & ":" & d & b), _
PlotBy:=xlRows
ActiveChart.SeriesCollection(1).XValues = Sheets(tabelle1).Range("B10:" & d & "10")
ActiveChart.SeriesCollection(1).Name = names
ActiveChart.Location Where:=xlLocationAsNewSheet
With ActiveChart
.HasAxis(xlCategory, xlPrimary) = True
.HasAxis(xlValue, xlPrimary) = True
End With
ActiveChart.Axes(xlCategory, xlPrimary).CategoryType = xlCategoryScale
With ActiveChart.Axes(xlCategory)
.HasMajorGridlines = False
.HasMinorGridlines = False
End With
With ActiveChart.Axes(xlValue)
.HasMajorGridlines = False
.HasMinorGridlines = False
End With
ActiveChart.HasLegend = False


m = Charts.Count
Charts(m).Select
Charts(m).Name = names
Sheets(names).Move after:=Sheets(tabelle1)

ActiveWorkbook.Sheets(tabelle1).Select
ActiveSheet.Cells(1, 1).Select

End Sub


Private Sub Ausführen_Click()
Call wert

End Sub

Antwort 6 von Saarbauer

Hallo,

gleiches Problem

https://supportnet.de/threads/1424357

Gruß

Helmut

Antwort 7 von VBA_Anfänger

Danke für den Hinweis funktioniert bis auf mein Kalenderproblem perfekt.

Gruß Stefan