Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 9th, 2011, 10:20 PM
Registered User
 
Join Date: Jul 2011
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Copying Characters to the Right of a Selected String in a .txt file

I am trying to make a VBA macro in Excel that searches for 5 characters to the right of a selected string in a .txt file and pastes it in the selected cell of choice. Can anyone help?

thanks
 
Old July 9th, 2011, 11:02 PM
Friend of Wrox
 
Join Date: Sep 2005
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

There are many ways to read content from TextFiles

Here you have a few of them

http://vbadud.blogspot.com/2007/06/v...h-leading.html

After you read the text to a string you can take the rightmost five characters using the Right function

right(MyString,5)

Cheers
Shasur
__________________
C# Code Snippets (http://www.dotnetdud.blogspot.com)

VBA Tips & Tricks (http://www.vbadud.blogspot.com)
 
Old July 10th, 2011, 03:38 PM
Registered User
 
Join Date: Jul 2011
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks for the help, can wait to get to it tonight!
 
Old July 12th, 2011, 09:46 PM
Registered User
 
Join Date: Jul 2011
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

So i guess i didn't explain the problem well enough...

I have a few text files that have the same format but different latitude, longitude and elevation values within them. Because the values are different in every text file i wanted to search for the text that is constant and copy the characters to the right of that constants.

e.g. sample of text = "latitude 123 23 53"
string = "latitude "
character that i want = "123 23 53"

paste the latitude value in cell A1
paste the longitude value in cell B1

-thank
 
Old July 12th, 2011, 09:52 PM
Friend of Wrox
 
Join Date: Sep 2005
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

If you have a clean set of entries you can use the following:

Code:
Sub SplitLat()
Dim sMixed As String
Dim sOutput As String
Dim sFind As String
sMixed = "latitude 123 23 53"
sFind = "latitude"
' Replace method
If InStr(sMixed, sFind) <> 0 Then ' If the text is found
    sOutput = Trim(Replace(sMixed, sFind, "", , , vbTextCompare))
End If
End Sub
Cheers
Shasur
__________________
C# Code Snippets (http://www.dotnetdud.blogspot.com)

VBA Tips &amp; Tricks (http://www.vbadud.blogspot.com)





Similar Threads
Thread Thread Starter Forum Replies Last Post
browse for all pdf file from selected folder and mail the selected pdf file suju_26pro VB.NET 0 May 6th, 2011 06:00 AM
Remove First and Last Characters from String if it Contains Those Characters DoriftuEvo Excel VBA 9 September 22nd, 2009 09:01 AM
Replacing characters in a string semilemon C# 2005 2 June 16th, 2006 11:31 PM
swapping characters in a string pritz VB How-To 1 August 22nd, 2005 12:19 PM
Copying selected files in vb sunitha_padmanabhan VB Components 2 November 15th, 2004 07:43 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.