Live-Forum - Die aktuellen Beiträge
Anzeige
Archiv - Navigation
1472to1476
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

suchen und weitersuchen

suchen und weitersuchen
31.01.2016 08:11:02
Sigi
Hallo,
ich möchte nach einem Begriff suchen, Makro ausführen und weitersuchen.
Leider weiss ich nicht wie ich das bewerkstelligen muß.
In Anlage Musterdatei zum besseren Verständnis.
Danke!
Gruß, Sigi
https://www.herber.de/bbs/user/103161.xlsm
Option Explicit
Private Declare PtrSafe Function SafeArrayGetDim Lib "oleaut32.dll" ( _
ByRef pArray() As Any) As Long
Dim lSp As Long, lSp1 As Long
Dim lRe As Long
Dim ii As Long
Private Sub CommandButton1_Click()
Dim arr()
Dim iRowU As Integer
Dim Anz As Integer
Dim Z As Integer
Dim AufAnz As Integer
Dim wksD As Object
Dim wksA As Object
Set wksD = Sheets("Data")
Set wksA = Sheets("Auswahl")
With wksA
For ii = 1 To .Cells(Rows.Count, 1).End(xlUp).Row
Range(.Cells(1, 2), .Cells(ii, 6)).Clear
Next ii
End With
With wksD
lSp = .Rows(1).Find(what:="ANG_P_NR", LookIn:=xlValues, lookat:=xlWhole).Column
lSp1 = .Rows(1).Find(what:="ANG_ANZAHL", LookIn:=xlValues, lookat:=xlWhole).Column
For ii = 2 To .Cells(Rows.Count, 1).End(xlUp).Row
If Not IsEmpty(.Cells(ii, 1)) And .Cells(ii, lSp) = UF1.cboProjNr.Value Then
lRe = ii
AufAnz = .Cells(lRe, lSp1).Value
Anz = lSp1 + 1
For Z = 1 To AufAnz
wksA.Cells(Z, 1) = .Cells(lRe, Anz)
wksA.Cells(Z, 2) = .Cells(lRe, Anz + 1)
wksA.Cells(Z, 3) = .Cells(lRe, Anz + 2)
wksA.Cells(Z, 4) = .Cells(lRe, Anz + 3)
wksA.Cells(Z, 5) = .Cells(lRe, Anz + 4)
wksA.Cells(Z, 6) = .Cells(lRe, Anz + 5)
Anz = Anz + 7
Next Z
End If
Z = Z + AufAnz
AufAnz = .Cells(lRe, lSp1).Value
Next ii
End With
With wksA
For ii = 1 To .Cells(Rows.Count, 4).End(xlUp).Row
If Not IsEmpty(.Cells(ii, 4)) Then
ReDim Preserve arr(0 To 6, 0 To iRowU)
arr(0, iRowU) = .Cells(ii, 1)
arr(1, iRowU) = FormatNumber(.Cells(ii, 2), 2)
arr(2, iRowU) = .Cells(ii, 3)
arr(3, iRowU) = .Cells(ii, 4)
arr(4, iRowU) = FormatNumber(.Cells(ii, 5), 2)
arr(5, iRowU) = FormatNumber(.Cells(ii, 6), 2)
arr(6, iRowU) = " "
iRowU = iRowU + 1
End If
Next ii
End With
With UF1
If SafeArrayGetDim(arr)  0 Then .lstAng.Column = arr
End With
End Sub
Private Sub UserForm_Initialize()
Dim dic As Object
Dim xKey As Variant
With Sheets("Data")
lSp = .Rows(1).Find(what:="ANG_P_NR", LookIn:=xlValues, lookat:=xlWhole).Column
Set dic = CreateObject("scripting.dictionary")
For ii = 2 To .Cells(Rows.Count, 1).End(xlUp).Row
If Not IsEmpty(.Cells(ii, lSp)) Then
xKey = .Cells(ii, lSp).Value
dic(xKey) = 0
End If
Next
For Each xKey In dic
UF1.cboProjNr.AddItem xKey
Next
dic.RemoveAll
Set dic = Nothing
End With
UF1.cboProjNr.ListIndex = -1
End Sub

4
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: suchen und weitersuchen
03.02.2016 07:41:19
Sigi
Hallo,
jetzt habe ich es ohne UF probiert doch wird es immer wieder falsch
eingelesen!
Wie muß ich das FindNext einsetzen?
Danke!
Gruß
Sigi
Sub Finden()
Dim lSp As Long, lSp1 As Long, lSp2 As Long, ii As Long
Dim C As Range
Dim sBegriff As String, FirstAddress As String
Dim Anz As Integer
Dim Z As Integer, X As Integer
Dim loEnde As Long, loEnde1 As Long
Dim AufAnz As Integer
Dim wksD As Object
Dim wksA As Object
Set wksD = Sheets("Data")
Set wksA = Sheets("Auswahl")
With wksA
For ii = 1 To .Cells(Rows.Count, 4).End(xlUp).Row
Range(.Cells(ii, 1), .Cells(ii, 6)).Clear
Next ii
End With
sBegriff = Sheets("Start").Cells(1, 1)
If sBegriff = "" Then Exit Sub
With wksD
lSp = 3
lSp1 = 5
lSp2 = 6
loEnde = wksA.Cells(Rows.Count, 4).End(xlUp).Row
Set C = .Columns(lSp).Find(What:=sBegriff, LookAt:=xlWhole, LookIn:=xlValues)
If C Is Nothing Then Exit Sub
If Not C Is Nothing Then
FirstAddress = C.Address
Set C = .Columns(lSp).FindNext(C)
AufAnz = .Cells(C.Row, lSp1).Value
For Z = loEnde To AufAnz
wksA.Cells(Z, 1).Value = .Cells(C.Row, lSp2).Value
wksA.Cells(Z, 2).Value = .Cells(C.Row, lSp2 + 1).Value
wksA.Cells(Z, 3).Value = .Cells(C.Row, lSp2 + 2).Value
wksA.Cells(Z, 4).Value = .Cells(C.Row, lSp2 + 3).Value
wksA.Cells(Z, 5).Value = .Cells(C.Row, lSp2 + 4).Value
wksA.Cells(Z, 6).Value = .Cells(C.Row, lSp2 + 5).Value
lSp2 = lSp2 + 7
Next Z
Do
Set C = .Columns(lSp).FindNext(C)
loEnde1 = wksA.Cells(Rows.Count, 4).End(xlUp).Row
AufAnz = .Cells(C.Row, lSp1).Value
For Z = loEnde1 To AufAnz
wksA.Cells(Z, 1).Value = .Cells(C.Row, lSp2).Value
wksA.Cells(Z, 2).Value = .Cells(C.Row, lSp2 + 1).Value
wksA.Cells(Z, 3).Value = .Cells(C.Row, lSp2 + 2).Value
wksA.Cells(Z, 4).Value = .Cells(C.Row, lSp2 + 3).Value
wksA.Cells(Z, 5).Value = .Cells(C.Row, lSp2 + 4).Value
wksA.Cells(Z, 6).Value = .Cells(C.Row, lSp2 + 5).Value
lSp2 = lSp2 + 7
Next Z
Loop While Not C Is Nothing And C.Address  FirstAddress
End If
End With
End Sub

Anzeige
noch offen?
06.02.2016 16:23:35
Michael
Hi Sigi,
ich glaube, ich weiß jetzt, was Du meinst:
Option Explicit
Sub Finden()
Dim lSp As Long, lSp1 As Long, lSp2 As Long, ii As Long
Dim C As Range
Dim sBegriff As String, FirstAddress As String
Dim Anz As Long
Dim Z As Long, X As Long
Dim loEnde As Long, loEnde1 As Long
Dim AufAnz As Long
Dim wksD As Worksheet
Dim wksA As Worksheet
Set wksD = Sheets("Data")
Set wksA = Sheets("Auswahl")
With wksA
ii = .Cells(Rows.Count, 4).End(xlUp).Row
.Range(.Cells(1, 1), .Cells(ii, 6)).Clear
End With
sBegriff = Sheets("Start").Cells(1, 1)
If sBegriff = "" Then Exit Sub
lSp = 3
lSp1 = 5
' lSp2 = 6   in Schleife versetzt
With wksD
Set C = .Columns(lSp).Find(What:=sBegriff, LookAt:=xlWhole, LookIn:=xlValues)
If Not C Is Nothing Then
FirstAddress = C.Address
Do
loEnde1 = wksA.Cells(wksA.Rows.Count, 4).End(xlUp).Row
If loEnde1  1 Then loEnde1 = loEnde1 + 1
' wenn nicht 1. Zeile, dann um 1 erhöhen: das ist die nächste, leere Zeile
AufAnz = .Cells(C.Row, lSp1).Value
lSp2 = 6
For Z = loEnde1 To AufAnz + loEnde1 - 1
wksA.Cells(Z, 1).Resize(1, 6).Value = .Cells(C.Row, lSp2).Resize(1, 6).Value
lSp2 = lSp2 + 7
Next Z
Set C = .Columns(lSp).FindNext(C)
Loop While Not C Is Nothing And C.Address  FirstAddress
End If
End With
End Sub
Aber wahrscheinlich hast Du es zwischenzeitlich ja schon selbst hinbekommen...
Schöne Grüße,
Michael

Anzeige
AW: noch offen?
06.02.2016 23:46:30
Sigi
Hallo Michael,
nein ich habe das Problem noch nicht gelöst.
Vielen Dank, jetzt funktioniert es.
Super!!!!
Gruß
Sigi

Das freut mich, Gruß zurück owT
07.02.2016 16:09:07
Michael

Links zu Excel-Dialogen

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige