Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default inport txt file automatically

Account Number Name 1 Property Address 1 wk1 wk2
1000192872 Mrs Sarah McLaren 1 Aitken Lane

I have an excel spreadsheet of above with 5000 account numbers in column A:
each week I have to import a txt file with some of these account numbers and
the amount paid in wk1 wk2 wk3 etc.
Can anyone show me how to do this using excel vba. I've got some knowledge
but not enough to do this by myself.
Thanks all.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default inport txt file automatically


Hi,

Just to get you started:

Sub Effe()
Dim iFno As Integer
Dim sFName As Variant
Dim sLine As String, sAccntNo As String
Dim vRow As Variant

vFName = Application.GetOpenFilename("Text Files (*.txt), *.txt")
If vFName = False Then Exit Sub

iFno = FreeFile()
Open vFName For Input As #iFno

Do While Not EOF(iFno)
Line Input #iFno, sLine
' account number is 1st 10 characters?
sAccntNo = Left$(sLine, 10)
' loop up the account number in the 1st column
vRow = Application.Match(sLine, ActiveSheet.Columns(1), 0)
If IsError(vRow) Then
MsgBox "Account " & sAccntNo & " does not exist", vbExclamation
Else
' week1 in column 4, week1's amount in input line at pos 22-26
ActiveSheet.Cells(vRow, 4) = CDbl(Mid$(sLine, 22, 5))
End If
Loop
Close #iFno
End Sub

With kind regards,
Ton Teun

--
Ton
-----------------------------------------------------------------------
TonT's Profile: http://www.officehelp.in/member.php?userid=4
View this thread: http://www.officehelp.in/showthread.php?t=66412
Visit - http://www.officehelp.in/archive/index.php | http://www.officehelp.in/index/index.ph

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel to inport data Danny Excel Worksheet Functions 1 April 26th 09 01:58 PM
Export/Inport Macros Tail Wind Excel Discussion (Misc queries) 2 January 5th 08 07:25 PM
Inport Outlook emails into Excel Richard Excel Discussion (Misc queries) 0 November 29th 06 04:18 PM
Inport from a variable file name shikamikamoomoo Excel Discussion (Misc queries) 1 March 22nd 06 12:29 AM
Inport of Microsoft Works Spreadsheets Perry Excel Discussion (Misc queries) 1 November 7th 05 02:53 AM


All times are GMT +1. The time now is 10:30 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"