I am having trouble with the code in red. I would like to first search for the first empty cell in column C on Sheet1 then search on another sheet for a specific value to move over to the first empty cell in column C in sheet1.
Option Explicit
Sub Open_My_Files()
Dim MyFile As String ' File to be appeneded
Dim MyPath As String ' Pathname to where CSV files are kept
Dim shS As Worksheet ' Source worksheet
Dim shD As Worksheet ' Destination worksheet
Dim lRow As Long
Dim sourceCol As Integer, rowCount As Integer, currentRow As Integer
Dim currentRowValue As String
Application.DisplayAlerts = False
' Initialize Variable
MyPath = "C:\\users\anthony777\desktop\"
MyFile = Dir(MyPath & "\*.csv")
' Loop through files
Do While MyFile <> ""
' Add a worksheet at the end of the current workbook and name it for the CSV fiel
Worksheets.Add After:=Sheets(Sheets.Count)
Set shD = Sheets(Sheets.Count)
shD.Name = Replace(MyFile, ".csv", "")
' Open the CSV file
Workbooks.Open MyPath & "\" & MyFile
' We can "get away with the following because we know the CSV file is active since we just opened it.
' We also know that CSV files only have one sheet
Set shS = ActiveWorkbook.Sheets(1)
' Copy all on this sheet
shS.Cells.Copy
' close the workbook
ActiveWorkbook.Close savechanges:=False
' The book knows that shD is part of it.
shD.Range("A1").PasteSpecial xlAll
'activate correct sheet
Worksheets("Inspection Data Sheet").Activate
'find the first blank cell in column c
sourceCol = 3
rowCount = Cells(Rows.Count, sourceCol).End(xlUp).Row
currentRowValue = Cells(currentRow, sourceCol).Value
If IsEmpty(currentRowValue) Or currentRowValue = "" Then
Cells(currentRow, sourceCol).Select
shS.Range("A1").Select
Cells.Find(What:="axis", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate
ActiveCell.Offset(1, 0).Select
End If
If ActiveCell = "TP" Then
ActiveCell.Offset(0, 3).Select
End If
' Get the next file
MyFile = Dir()
Loop
Application.DisplayAlerts = True
End Sub
Bookmarks