VBA_Newbie123
New Member
- Joined
- May 20, 2017
- Messages
- 9
Hi,
I have the below code where I am selecting a sheet to copy data from but it has been updated with an output now in cell J1 on Sheet1 causing my macro to fall over. I really just want the cell deleted before the next step where it can continue again. I have been trying to add in below;
to the full code;
any help would be greatly appreciated
I have the below code where I am selecting a sheet to copy data from but it has been updated with an output now in cell J1 on Sheet1 causing my macro to fall over. I really just want the cell deleted before the next step where it can continue again. I have been trying to add in below;
VBA Code:
Range("J1").Select
Selection.ClearContents
to the full code;
VBA Code:
Sub Sform()
UserForm1.Show False
End Sub
Sub importcsv()
Dim fd As Office.FileDialog
Set fd = Application.FileDialog(msoFileDialogFilePicker)
With fd
.Filters.Clear
.Title = "select a csv file"
.Filters.Add "CSV", "*.csv", 1
.AllowMultiSelect = False
Dim sFile As String
If .Show = True Then
sFile = .SelectedItems(1)
End If
End With
'import CSV from FileDialog
If sFile <> "" Then
Open sFile For Input As #1
row_number = 0
Do Until EOF(1)
Line Input #1, LineFromFile
lineitems = Split(LineFromFile, ",")
Application.Range("datarange").Cells(row_number, 1).Value = lineitems(0)
Application.Range("datarange").Cells(row_number, 2).Value = lineitems(1)
Application.Range("datarange").Cells(row_number, 3).Value = lineitems(2)
Application.Range("datarange").Cells(row_number, 4).Value = lineitems(3)
Application.Range("datarange").Cells(row_number, 5).Value = lineitems(4)
Application.Range("datarange").Cells(row_number, 6).Value = lineitems(5)
Application.Range("datarange").Cells(row_number, 7).Value = lineitems(6)
Application.Range("datarange").Cells(row_number, 8).Value = lineitems(7)
Application.Range("datarange").Cells(row_number, 9).Value = lineitems(8)
row_number = row_number + 1
Loop
Close #1
End If
End Sub
Sub copydata()
Dim Ah As Worksheet
Set Ah = ThisWorkbook.Sheets("Data")
Dim lastrow As Long
lastrow = Application.WorksheetFunction.CountA(Ah.Range("i:i")) + 1
Ah.Range("A2").Copy
Ah.Range("A3" & lastrow).PasteSpecial xlPasteValues
End Sub
any help would be greatly appreciated