In fisierul Test am introdus un cod care importa in coloana A din Test valorile (numere formate din cate opt cifre) din coloana A din Sursa.
Ce vreau sa se intample: daca prima cifra din seria de opt cifre din fiecare celula nu este 9, celula sa fie stearsa.
Treaba este ca la o rulare codul nu sterge toate celulele care ma intereseaza. Daca rulez codul de stergere de mai multe ori ajung la rezultatul dorit.
Cod: Selectaţi tot
Sub ImportRange()
'Import Range A2:A65536 din fisierul Sursa
Dim customerBook As Workbook
Dim filter As String
Dim caption As String
Dim customerFilename As String
Dim customerWorkbook As Workbook
Dim targetWorkbook As Workbook
Set targetWorkbook = Application.ActiveWorkbook
filter = "Text files (*.xlsx),*.xlsx"
caption = "Please Select an input file "
customerFilename = Application.GetOpenFilename(filter, , caption)
On Error Resume Next
Set customerWorkbook = Application.Workbooks.Open(customerFilename)
Dim targetSheet As Worksheet
Set targetSheet = targetWorkbook.Worksheets(1)
Dim sourceSheet As Worksheet
Set sourceSheet = customerWorkbook.Worksheets(1)
targetSheet.Range("A2:A65536").Value = sourceSheet.Range("A2:A65536").Value
customerWorkbook.Close
' Stergele celule CARE NU INCEP CU 9
Dim rng As Range, cell As Range
Set rng = Range("A2:A65536")
For Each cell In rng
If Not cell.Value = "" Then
If Not Left(cell, 1) = "9" Then
cell.Delete
End If
End If
Next cell
End Sub
Multumesc.