Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-13-2016, 08:00 PM
macropod's Avatar
macropod macropod is offline Runtime error '9': Subscript out of Range Windows 7 64bit Runtime error '9': Subscript out of Range Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

It's difficult to work out what your code is supposed to do, since you populate some variables, but then don't use them (e.g. lastRow), and use others that haven't been populated anywhere (e.g. row), plus you have a lot of circumlocution in the code (multiple array creations & population).



Perhaps you want to achieve something like:

Code:
Private Sub CommandButton21_Click()

Dim dataFile As String, dataText As String, StrData As String, Rng As Range, StrErr As String
 
dataFile = Application.GetOpenFilename() 'Select the text file
Open dataFile For Input As #1 'Open the text file as "#1"
  Do Until EOF(1)
    Line Input #1, StrData 'Read in the text file, a line at a time
    Rng = Sheets("ALL-Jul2014").Columns("A").Find(what:=Replace(Mid(StrData, 6, 6), "_", "-"), _
      LookIn:=xlValues, lookat:=xlValues) ' Find the row in Column A
    If Not Rng Is Nothing Then
      Rng.Offset(0, 1).Value = StrData ' Output the data to column B
    Else
      StrErr = StrErr & vbCr & StrData
    End If
  Loop
Close #1
 
Set Rng = Nothing ' Cleanup
If StrErr <> "" Then MsgBox ("No records found for " & StrData) 'Error Report
End Sub
PS: When posting code, please use the code tags, indicated by the # button on the posting menu. Without them, your code loses much of whatever structure it had.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Tags
run-time error, subscript out of range



Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA Conditional Formatting Error (Subscript out of Range)) tinfanide Excel Programming 1 05-15-2015 08:12 AM
Runtime error '9': Subscript out of Range Runtime error 91 waldux Word VBA 1 03-04-2011 11:25 PM
Runtime error 5487 - Word cannot complete the save to to file permission error franferns Word 0 11-25-2009 05:35 AM
Runtime error '9': Subscript out of Range Subscript out of range error KHTAY Excel 6 03-28-2009 11:18 PM
Runtime error '9': Subscript out of Range Mysterious "Subscript out of range" error rnstewart Excel 4 12-29-2005 01:04 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:06 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft