nihonjin2000
09-20-2015, 11:47 AM
hi I have a problem with vba code and I need help.
I woudl like to make a macro:
1) open files from folder
2) find text : for example : ;;dt;ct;;;;;
3) delete that text and everything below text.
4) save file and close documents
I can not create number 3 ( delete that text and everything below text.)
Please Help! I will be grateful
This is my vba code.
Sub Usuwanie_Pierwszego_wiersza()
' 4 zmienne
Dim Nazwa_pliku As String
Dim Kontynuacja As Variant
Dim WS As Worksheet
Dim komorka1 As Range
' path
Nazwa_pliku = Dir("*.csv*")
' msgbox window
Kontynuacja = MsgBox("To makro usunie 3 wiersze z katalogu roboczego." & vbLf & _
"in " & Application.DefaultFilePath & ", zaczynając od pliku : " & vbLf & _
Nazwa_pliku & " czy kontynuować?", vbYesNo, "UWAGA!")
' msgbox-choose
If Kontynuacja - vbNo Then Exit Sub
Application.DisplayAlerts = False
'open file
Workbooks.Open Nazwa_pliku
Application.StatusBar = Nazwa_pliku & "opened."
'find text
ActiveSheet.Cells.Find(What:=";;dt;ct", After:=ActiveCell, LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=True).Activate
Set komorka1 = ActiveCell
'ActiveSheet.ActiveCell.Delete--??????
???
'Close file
ActiveWorkbook.Close True
Application.StatusBar = Nazwa_pliku & "closed."
Nazwa_pliku = Dir()
Application.DisplayAlerts = False
Application.StatusBar = False
End Sub
I woudl like to make a macro:
1) open files from folder
2) find text : for example : ;;dt;ct;;;;;
3) delete that text and everything below text.
4) save file and close documents
I can not create number 3 ( delete that text and everything below text.)
Please Help! I will be grateful
This is my vba code.
Sub Usuwanie_Pierwszego_wiersza()
' 4 zmienne
Dim Nazwa_pliku As String
Dim Kontynuacja As Variant
Dim WS As Worksheet
Dim komorka1 As Range
' path
Nazwa_pliku = Dir("*.csv*")
' msgbox window
Kontynuacja = MsgBox("To makro usunie 3 wiersze z katalogu roboczego." & vbLf & _
"in " & Application.DefaultFilePath & ", zaczynając od pliku : " & vbLf & _
Nazwa_pliku & " czy kontynuować?", vbYesNo, "UWAGA!")
' msgbox-choose
If Kontynuacja - vbNo Then Exit Sub
Application.DisplayAlerts = False
'open file
Workbooks.Open Nazwa_pliku
Application.StatusBar = Nazwa_pliku & "opened."
'find text
ActiveSheet.Cells.Find(What:=";;dt;ct", After:=ActiveCell, LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=True).Activate
Set komorka1 = ActiveCell
'ActiveSheet.ActiveCell.Delete--??????
???
'Close file
ActiveWorkbook.Close True
Application.StatusBar = Nazwa_pliku & "closed."
Nazwa_pliku = Dir()
Application.DisplayAlerts = False
Application.StatusBar = False
End Sub