| | Post: 39 | Registrato il: 18/03/2020
| Età: 56 | Utente Junior | 2016 | | OFFLINE | |
|
09/11/2021 11:19 | |
Buongiorno ho fatto questa macro che mi permette di esportare una colonna in un determinato formato.
Vorrei solo che prima di effettuare ciò, facesse un controllo e non mi facesse esportare nulla se nell'intervallo delle celle di excel ci fosse un ND o un valore uguale a 0
Sub WRITESETUP_01()
'Setup file generation procedure for AC F2 Configurator
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
PrecValue = Target.Cells(1, 1).Value
End Sub
Dim template_workbook As Workbook
Dim rng As Range, i As Integer, j As Integer
Dim cellValue As String
Dim model_name As String, track_name As String
Dim setuppath As String
Dim setupname As Variant
Application_path = Application.ActiveWorkbook.Path
model_name = ThisWorkbook.Sheets(2).Range("B9")
track_name = ThisWorkbook.Sheets(2).Range("B10")
setuppath = "C:\Setups\"
namecode = Range("B3")
'setupname = InputBox("Setup name", "Saving setup", "noname")
'setupfile = setuppath & model_name & "_" & track_name & "_" & setupname & ".txt"
'MsgBox setupfile
setupfile = Application.GetSaveAsFilename("E:\export\Sim Session Setups\F2\" & namecode, fileFilter:="Setup file (*.txt), *.txt")
If setupfile = False Then
Exit Sub
End If
Set setupfile_data = Range("A4:B74")
Open setupfile For Output As #1
For i = 1 To setupfile_data.Rows.Count
For j = 1 To setupfile_data.Columns.Count
cellValue = setupfile_data.Cells(i, j).Value & Chr(9)
If j = setupfile_data.Columns.Count Then
Print #1, cellValue
Else
Print #1, cellValue;
End If
Next j
Next i
Close #1
Application.ScreenUpdating = True
MsgBox ("SIM Session setup created") |
|
| | Post: 1.162 | Registrato il: 16/08/2015
| Città: CORDENONS | Età: 67 | Utente Veteran | Excel 2016-32bit Win11 | | OFFLINE |
|
09/11/2021 12:19 | |
Aggiungi queste poche righe all'interno della tua macro e riprova. In pratica, prima di passare al traferimento dei dati si controlla il contenuto del range. [...]
Set setupfile_data = Range("A4:B74")
Dim check As Boolean
'Dim rng As Range 'non serve dato che è già stata dichiarata)
For Each rng In setupfile_data
If IsError(rng.Value) Then 'controlla se errore (#N/D, #DIV/0!, ecc.)
check = True
Exit For
ElseIf rng.Value = 0 Then 'controlla se vuoto o 0
check = True
Exit For
End If
Next
If check = True Then
MsgBox "Ci sono delle incongruenze nei dati ! Ricontrolla !"
Exit Sub
End If
Open setupfile For Output As #1
[...]
______________________________________________________________
C'è chi fa le COSE a CASO e chi fa CASO alle COSE (Ignoto) |
|
|