Live-Forum - Die aktuellen Beiträge
Anzeige
Archiv - Navigation
1244to1248
Aktuelles Verzeichnis
Verzeichnis Index
Übersicht Verzeichnisse
Vorheriger Thread
Rückwärts Blättern
Nächster Thread
Vorwärts blättern
Anzeige
HERBERS
Excel-Forum (Archiv)
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender
Inhaltsverzeichnis

ActiveCell

ActiveCell
Josef
Hallo!
Nachdem ich in der Hilfe das so verstanden habe, dass ActiveCell nur dann funktioniert, wenn das Arbeitsblatt aktiviert ist, hätte ich dazu bitte folgende Frage:
Was müßte ich statt ActiveCell verwenden, wenn das entsprechende Arbeitsblatt nicht im Vordergrund ist sonder geöffnet in einer anderen Arbeitsmappe liegt?
Danke
josef

8
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Benutzer
Anzeige
AW: ActiveCell
04.01.2012 09:25:29
Thomas
Set a = Workbooks("AndereDatei.xls").Sheets("Tabelle1")
a.Cells(1, 1) 'Für die Zelle A1 in der anderen Datei in der Tabelle1
oder: Workbooks("AndereDatei.xls").Sheets("Tabelle1").Cells(1, 1).Value
VG Thomas S.
AW: ActiveCell
04.01.2012 09:50:59
Josef
Hallo Thomas!
Danke für Deine Antwort.
Funktioniert leider nicht ganz
Bei der Zeile "wks.Cells(1, 1).Offset(1, 0).Select" bekomme ich einen Fehler bei Select
Setze ich diese Zeile außer Kraft dann geht in Excel nichts mehr.
Hier mal der VBA Code
Private Sub TextBox35_AfterUpdate()
Dim wks As Worksheet
Set wks = Workbooks("Masterfile.xls").Worksheets("Tabelle1")
'Sheets("Tabelle1").Select
Const col_datsatz = 1 ' Positionsnummer
Const col_prod = 7 ' Kolonne Hersteller
Const col_posnr = 3 ' Kolonne Kategorie
Const col_preis = 4 'Bundesländer
Const col_bl = 5 'Preis
Const first_row = 2 ' Zeile mit erstem Product
Dim found As Integer
Dim entry_is As Integer
TextBox33 = ""
TextBox40 = ""
Cells(first_row, col_datsatz).Select
'Do Until ActiveCell = "" ' Schleife bis Zelle in Kolonne A leer
Do Until wks.Cells(1, 1) = "" ' Schleife bis Zelle in Kolonne A leer
If TextBox35.Text  "" Then
'If InStr(1, ActiveCell.Offset(0, 8), TextBox35.Text, vbTextCompare) > 0 Then
If InStr(1, wks.Cells(1, 1).Offset(0, 8), TextBox35.Text, vbTextCompare) > 0 Then
found = found + 1
End If
Else
found = found + 1
End If
If found = 1 Then
'ListBox1.AddItem ActiveCell
ListBox1.AddItem wks.Cells(1, 1)
entry_is = ListBox1.ListCount – 1
'ListBox1.List(entry_is, 1) = ActiveCell.Offset(0, 2)
'ListBox1.List(entry_is, 2) = ActiveCell.Offset(0, 3)
'ListBox1.List(entry_is, 3) = ActiveCell.Offset(0, 4)
'ListBox1.List(entry_is, 4) = ActiveCell.Offset(0, 5)
'ListBox1.List(entry_is, 5) = ActiveCell.Offset(0, 6)
'ListBox1.List(entry_is, 6) = ActiveCell.Offset(0, 7)
'ListBox1.List(entry_is, 7) = ActiveCell.Offset(0, 8)
'ListBox1.List(entry_is, 8) = ActiveCell.Offset(0, 26)
'ListBox1.List(entry_is, 9) = ActiveCell.Offset(0, 27)
'ListBox1.List(entry_is, 10) = ActiveCell.Offset(0, 27)
ListBox1.List(entry_is, 1) = wks.Cells(1, 1).Offset(0, 2)
ListBox1.List(entry_is, 2) = wks.Cells(1, 1).Offset(0, 3)
ListBox1.List(entry_is, 3) = wks.Cells(1, 1).Offset(0, 4)
ListBox1.List(entry_is, 4) = wks.Cells(1, 1).Offset(0, 5)
ListBox1.List(entry_is, 5) = wks.Cells(1, 1).Offset(0, 6)
ListBox1.List(entry_is, 6) = wks.Cells(1, 1).Offset(0, 7)
ListBox1.List(entry_is, 7) = wks.Cells(1, 1).Offset(0, 8)
ListBox1.List(entry_is, 8) = wks.Cells(1, 1).Offset(0, 26)
ListBox1.List(entry_is, 9) = wks.Cells(1, 1).Offset(0, 27)
End If
'ActiveCell.Offset(1, 0).Select
wks.Cells(1, 1).Offset(1, 0).Select
Loop
End Sub

Danke
Josef
Anzeige
AW: ActiveCell
04.01.2012 10:21:53
Thomas
Hallo Josef
Du musst weg von der ActiveCell. Das ist der Fehler. Du musst das anders lösen.
Mit der Set Anweisung bist Du doch schon auf dem richtigen Weg.
Nach dem Muster würde ich die anderen Bezüge auch herstellen.
VG Thomas
AW: ActiveCell
04.01.2012 10:37:37
Josef
Hallo Thomas!
Wenn du denn Code ansiehst habe ich die ActiveCell ja schon stillgelegt und mit Deiner Lösung aufgemacht.
Josef
AW: ActiveCell
04.01.2012 15:37:18
fcs
Hallo Josef,
"Select" funktioniert nur, wenn das zu selektierende Objekt (Zelle, Tabelle, etc.) sich im aktiven Excel-Fenster befindet.
Wenn man unbedingt eine Select-Anweisung unter VBA ausführen will, dann muss ggf. vorher das entsprechende übergeordnete Objekt (Arbeitsmappe und/oder Tabellenblatt/Diagramm) aktiviert werden.
Meistens kann man aber so programmieren, dass man nicht selektieren muss.
In deiner Prozedur hab ich den Sinn der Variablen "found" noch nicht ganz nachvollziehen können.
Ansonsten muss du in der Schleife einen Zähler einbauen für die Zeilen der bei jedem Schleifendurchlauf um 1 erhöht wird.
Gruß
Franz
Private Sub TextBox35_AfterUpdate()
Dim wks As Worksheet, wbMaster As Workbook
Dim wbAktiv As Workbook
Set wbAktiv = ActiveWorkbook 'Nur erforderlich, wenn mit Activate zwischen den beiden Mappen  _
_
umgeschaltet werden soll.
Set wbMaster = Workbooks("Masterfile.xls")
Set wks = wbMaster.Worksheets("Tabelle1")
'Sheets("Tabelle1").Select
Const col_datsatz = 1 ' Positionsnummer
Const col_prod = 7 ' Kolonne Hersteller
Const col_posnr = 3 ' Kolonne Kategorie
Const col_preis = 4 'Bundesländer
Const col_bl = 5 'Preis
Const first_row = 2 ' Zeile mit erstem Product
Dim found As Integer
Dim lngCount As Long
Dim entry_is As Integer
TextBox33 = ""
TextBox40 = ""
Do Until wks.Cells(first_row + lngCount, 1) = "" ' Schleife bis Zelle in Kolonne A leer
If TextBox35.Text  "" Then
If InStr(1, wks.Cells(first_row + lngCount, , 1).Offset(0, 8), _
TextBox35.Text, vbTextCompare) > 0 Then
found = found + 1
End If
Else
found = found + 1
End If
If found = 1 Then
'ListBox1.AddItem ActiveCell
With wks.Cells(first_row + lngCount, 1)
ListBox1.AddItem .Value
entry_is = ListBox1.ListCount – 1
ListBox1.List(entry_is, 1) = .Offset(0, 2)
ListBox1.List(entry_is, 2) = .Offset(0, 3)
ListBox1.List(entry_is, 3) = .Offset(0, 4)
ListBox1.List(entry_is, 4) = .Offset(0, 5)
ListBox1.List(entry_is, 5) = .Offset(0, 6)
ListBox1.List(entry_is, 6) = .Offset(0, 7)
ListBox1.List(entry_is, 7) = .Offset(0, 8)
ListBox1.List(entry_is, 8) = .Offset(0, 26)
ListBox1.List(entry_is, 9) = .Offset(0, 27)
End With
End If
found = 0             '?
lngCount = lngCount + 1
Loop
End Sub

Anzeige
AW: ActiveCell
05.01.2012 06:47:45
Josef
Hallo!
HJerzlichen Dank für Deine Antwort. Nach dem rein kopieren Deines Codes erhalte ich mit
entry_is = ListBox1.ListCount – 1
eine rote Zeile , also einen Fehler.
Danke
Josef
entferne mal die Leerzeichen vor und nach dem "-"
05.01.2012 07:32:19
Matthias
oT
AW: entferne mal die Leerzeichen vor und nach dem "-"
05.01.2012 12:33:09
Josef
Hallo Matthias!
Danke für Deine Antwort. Werde es gleich koorigieren und danach nochmals probieren.
Josef

Links zu Excel-Dialogen

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige