Mijn vraag
Ik heb te maken met standaard excel documenten waarvan ik wil controleren of in kollom E bepaalde gebwouwnummers voorkomen. (in totaal 80 stuks die ik in een apart excel document heb staan).
ik wil dit graag toevoegen aan een script dat ik al heb waarmee ik de inhoud het document naar een tekstfile print om te kunnen mailen. Wie kan me helpen
Relevante software en hardware die ik gebruik
Momenteel heb ik al het volgende script:
Sub create_text_file()
'Object to use as folder
Dim fld As Object
Set fld = CreateObject("Scripting.FileSystemObject")
'using create text file method
Dim myFile As Object
Set myFile = fld.CreateTextFile("H:\my_aanmeld_file\myTextFile.txt", True)
End Sub
Sub data_to_text_file()
'variables that you need to use in the code
Dim TextFile As Integer
Dim iCol As Integer
Dim myRange As Range
Dim cVal As Range
Dim i As Integer
Dim myFile As String
'define the range that you want to write
Set myRange = Range("B14:B100")
iCol = myRange.Count
'path to the text file (MAKE SURE TO CHANGE IT)
myFile = "H:\my_aanmeld_file\myTextfile.txt"
'define FreeFile to the variable file number
TextFile = FreeFile
'using append command to add text to the end of the file
Open myFile For Output As TextFile
'loop to add data to the text file
For i = 13 To iCol
Print #TextFile, Cells(i, 4),
Print #TextFile, "Gebouw: "; Cells(i, 5),
Print #TextFile, "Startdatum: "; Cells(i, 12),
Print #TextFile, "Einddatum: "; Cells(i, 14),
Print #TextFile, "Reden voor bezoek: "; Cells(i, 16),
Print #TextFile, "E-mailadres bezoeker: "; Cells(i, 18)
Next i
'close command to close the text file after adding data
Close #TextFile
End Sub
Sub TextfileCompleet()
Call create_text_file 'Macro1
Call data_to_text_file 'Macro2
End Sub
Wat ik al gevonden of geprobeerd heb
Sub Find_Matches()
Dim CompareRange As Variant, x As Variant, y As Variant
' Set CompareRange equal to the range to which you will
' compare the selection.
Set CompareRange = Workbooks("PERSONAL").Worksheets("Blad1").Range("A1:A100")
' NOTE: If the compare range is located on another workbook
' or worksheet, use the following syntax.
' Set CompareRange = Workbooks("Book2"). _
' Worksheets("Sheet2").Range("C1:C5")
' Loop through each cell in the selection and compare it to
' each cell in CompareRange.
For Each x In Selection
For Each y In CompareRange
If x = y Then x.Offset(0, 1) = x
Next y
Next x
End Sub
Echter loop ik vast op de aanpassing om dit gedeelt toegevoegd te krijgen. De uitkomt van de vergelijking hoeft niet geprint te worden naar de tekstfile, alleen melding dat een van de gebouw nummers er in staat is al voldoende.
Alvast bedankt voor jullie hulp
mvg. Hennie
Ik heb te maken met standaard excel documenten waarvan ik wil controleren of in kollom E bepaalde gebwouwnummers voorkomen. (in totaal 80 stuks die ik in een apart excel document heb staan).
ik wil dit graag toevoegen aan een script dat ik al heb waarmee ik de inhoud het document naar een tekstfile print om te kunnen mailen. Wie kan me helpen
Relevante software en hardware die ik gebruik
Momenteel heb ik al het volgende script:
Sub create_text_file()
'Object to use as folder
Dim fld As Object
Set fld = CreateObject("Scripting.FileSystemObject")
'using create text file method
Dim myFile As Object
Set myFile = fld.CreateTextFile("H:\my_aanmeld_file\myTextFile.txt", True)
End Sub
Sub data_to_text_file()
'variables that you need to use in the code
Dim TextFile As Integer
Dim iCol As Integer
Dim myRange As Range
Dim cVal As Range
Dim i As Integer
Dim myFile As String
'define the range that you want to write
Set myRange = Range("B14:B100")
iCol = myRange.Count
'path to the text file (MAKE SURE TO CHANGE IT)
myFile = "H:\my_aanmeld_file\myTextfile.txt"
'define FreeFile to the variable file number
TextFile = FreeFile
'using append command to add text to the end of the file
Open myFile For Output As TextFile
'loop to add data to the text file
For i = 13 To iCol
Print #TextFile, Cells(i, 4),
Print #TextFile, "Gebouw: "; Cells(i, 5),
Print #TextFile, "Startdatum: "; Cells(i, 12),
Print #TextFile, "Einddatum: "; Cells(i, 14),
Print #TextFile, "Reden voor bezoek: "; Cells(i, 16),
Print #TextFile, "E-mailadres bezoeker: "; Cells(i, 18)
Next i
'close command to close the text file after adding data
Close #TextFile
End Sub
Sub TextfileCompleet()
Call create_text_file 'Macro1
Call data_to_text_file 'Macro2
End Sub
Wat ik al gevonden of geprobeerd heb
Sub Find_Matches()
Dim CompareRange As Variant, x As Variant, y As Variant
' Set CompareRange equal to the range to which you will
' compare the selection.
Set CompareRange = Workbooks("PERSONAL").Worksheets("Blad1").Range("A1:A100")
' NOTE: If the compare range is located on another workbook
' or worksheet, use the following syntax.
' Set CompareRange = Workbooks("Book2"). _
' Worksheets("Sheet2").Range("C1:C5")
' Loop through each cell in the selection and compare it to
' each cell in CompareRange.
For Each x In Selection
For Each y In CompareRange
If x = y Then x.Offset(0, 1) = x
Next y
Next x
End Sub
Echter loop ik vast op de aanpassing om dit gedeelt toegevoegd te krijgen. De uitkomt van de vergelijking hoeft niet geprint te worden naar de tekstfile, alleen melding dat een van de gebouw nummers er in staat is al voldoende.
Alvast bedankt voor jullie hulp
mvg. Hennie