adding cell delete before next code

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;

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 :)
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
it has been updated with an output now in cell J1 on Sheet1 causing my macro to fall over
Hi, rather than any guessing challenge :rolleyes: where the error raises ?!​
As I do not think it's relative to J1 cell but obviously just 'cause of some bad logic …​
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,915
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top