Inputting data to next blank cell

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

My basic code for inputting data into 4 columns is below. The data is in 3
text documents (am249_1, am249_2, am249_3). This works.

I need some code which will move down to the next blank cell in a column and
insert the next data file after any data already present in the column. I
need it so the data files can be opened in any order and that it will detect
if data is already open.

'Inputbox asking for filename
Dim Name
Name = InputBox("Please enter the filename you would like to open:", , , 100)
'Opening files
If Name = "am249_1" Then
Open "C:\Documents and Settings\MC\Desktop\VBA assignment\am249_1.txt" For
Input As #1
Linect = ActiveCell
Do Until EOF(1)
Input #1, t1, t2, t3, t4
Range("A1").Offset(Linect, 0) = t1
Range("B1").Offset(Linect, 0) = t2
Range("C1").Offset(Linect, 0) = t3
Range("D1").Offset(Linect, 0) = t4
Linect = Linect + 1
Loop
Close #1
End If
If Name = "am249_2" Then
Open "C:\Documents and Settings\MC\Desktop\VBA assignment\am249_2.txt" For
Input As #2
Linect = 0
Do Until EOF(2)
Input #2, t1, t2, t3, t4
Range("A1").Offset(Linect, 0) = t1
Range("B1").Offset(Linect, 0) = t2
Range("C1").Offset(Linect, 0) = t3
Range("D1").Offset(Linect, 0) = t4
Linect = Linect + 1
Loop
Close #2
End If
If Name = "am249_3" Then
Open "C:\Documents and Settings\MC\Desktop\VBA assignment\am249_3.txt" For
Input As #3
Linect = 0
Do Until EOF(3)
Input #3, t1, t2, t3, t4
Range("A1").Offset(Linect, 0) = t1
Range("B1").Offset(Linect, 0) = t2
Range("C1").Offset(Linect, 0) = t3
Range("D1").Offset(Linect, 0) = t4
Linect = Linect + 1
Loop
Close #3
End If


Thanks in advance.
 
not sure I understand what you are needing exactly, but for entry into
the empty cell at the end of a column, i like to use:

Dim lRow as integer

lRow = Activesheet.Cells(Rows.Count, 1).End(xlUp).Row

Activesheet.cells(lRow + 1, 1).value = "blah"

Don't know if that helps, but it's a routine I use rather religously in
all manner of tasks ~
 
Back
Top