ich habe einen Code für einen Export von Zahlen in eine andere Tabelle geschrieben und
brauche bitte Hilfe bei der Formulierung einer Variable.
Die Variable lngCnt gibt an wie oft eine Schleife ablaufen soll.
Momentan ist ihr noch ein zellwert zugeordnet.
Jetzt möchte ich aber dass die Variable eine zahl ist, die sich erst erechnet werden muss.
Hier mein Code mit den gewünschten Bedingungen für die Erechnung der Zahl, als Kommentar eingefügt.
Sub importData()
Dim objFiles() As Object
Dim objWB As Workbook, objSh As Worksheet
Dim lngRow As Long, lngCnt As Long, lngIndex As Long, lngRet As Long
Dim strTab As String, strPath As String
Dim vntRet As Variant
Dim lngN As Variant
Dim antwort As Long
If ActiveSheet.ProtectContents = True Then
MsgBox "Blattschutz bitte unter Extras -> Schutz aufheben"
End
End If
antwort = MsgBox("Soll der Import gestartet werden?", vbYesNo)
If antwort = vbYes Then
End If
If antwort = vbNo Then
End
End If
If ActiveSheet.Range("$I$1").Value 0 Then
Set objSh = ThisWorkbook.Sheets("Tabelle1") 'Name der Zieltabelle - Anpassen!
lngCnt = objSh.Range("I1")
'Hier soll statt lngCnt=objSh.Range ("I1") die Anzahl der Zellen, die in Worksheet objWB
'von A24:A500, >= Zahl "C1" (objSh) sind und
'=" & objSh.Range("C1") And "
lngRow = Application.Max(18, objSh.Cells(objSh.Rows.Count, 18).End(xlUp).Row + 1)
For lngIndex = 0 To lngRet - 1
If Not objFiles(lngIndex) = ThisWorkbook.FullName Then
Set objWB = Workbooks.Open(objFiles(lngIndex))
If SheetExist(strTab, objWB) Then
With objWB.Sheets(strTab)
vntRet = Application.Match(objSh.Range("C1"), .Range("A24:A500"), 0)
If IsNumeric(vntRet) Then
For lngN = 0 To lngCnt - 1
If .Cells(vntRet + lngN, 2) "" And .Cells(vntRet + lngN, 3) "" Then
.Cells(vntRet + lngN, 1).Copy objSh.Cells(lngRow, 3)
.Cells(vntRet + lngN, 2).Copy objSh.Cells(lngRow, 5)
.Cells(vntRet + lngN, 3).Copy objSh.Cells(lngRow, 6)
.Cells(vntRet + lngN, 4).Copy objSh.Cells(lngRow, 7)
.Cells(vntRet + lngN, 7).Copy objSh.Cells(lngRow, 8)
objSh.Cells(lngRow, 4) = .Range("B3").Value
objSh.Cells(lngRow, 1) = "OC"
objSh.Cells(lngRow, 12) = "ja"
lngRow = lngRow + 1
End If
Next
End If
End With
End If
objWB.Close False
End If
Next
End If
MsgBox "Der Import ist erfolgt"
ErrExit:
With Err
If .Number 0 Then MsgBox "Fehler " & .Number & vbLf & vbLf & _
.Description & vbLf & vbLf & "In Prozedur (importData) in Modul Modul1", _
vbExclamation, "Fehler in Makro bitte im VBA Code nachsehen"
End With
GMS True
Set objWB = Nothing
Set objSh = Nothing
End Sub
Leider fehlt mir das Verständnis dafür.
Über jeden Hinweis bzw. hilfe würde ich mich sehr freuen.
Viele Grüße aus München,
Jeron