Notices
Computer & Technology Related Post here for help and discussion of computing and related technology. Internet, TVs, phones, consoles, computers, tablets and any other gadgets.

Excel - Visual Basic (remove characters)

Thread Tools
 
Search this Thread
 
Old Oct 26, 2004 | 12:53 AM
  #1  
velohead66's Avatar
velohead66
Thread Starter
Scooby Regular
 
Joined: Oct 2002
Posts: 565
Likes: 1
From: ex UK [SE], now Sunshine State [QLD,AUS]
Question Excel - Visual Basic (remove characters)

I need to write a script, that amonst other things will do the following.

GoTo a certain cell
Capture the contents (ie text)
Remove the trailing character (a single space)
Past the new contents (ie text)
Move on to another cell.

eg
capture "$122.00 " [ <- note space character ]
paste "$122.00" [ <- note NO space character ]
move to next cell
capture "$212122.00 " [ <- note space character ]
paste "$212122.00" [ <- note NO space character ]
move to next cell
etc etc

Moving is ok
Capture is ok
Paste is ok

Need help for the deleting of the " " character [space character]

OK, an easy one, but any tips, or code, please.
Thank You VB Gurus.
Reply
Old Oct 26, 2004 | 09:47 AM
  #2  
Sub97's Avatar
Sub97
Scooby Regular
 
Joined: Oct 2002
Posts: 809
Likes: 0
Default

string = RTrim(string) - if you only want the space from the right hand side taken off, or

string = Trim(string) - if you want spaces from either end taken off.

Cheers

Steve
Reply
Old Oct 26, 2004 | 08:08 PM
  #3  
Lum's Avatar
Lum
Scooby Regular
 
Joined: May 2004
Posts: 1,386
Likes: 0
From: South Wales
Default

String = Left(String,Len(String)-1) if you want to remove the last character even if it isn't a space
Reply
Old Oct 26, 2004 | 08:18 PM
  #4  
velohead66's Avatar
velohead66
Thread Starter
Scooby Regular
 
Joined: Oct 2002
Posts: 565
Likes: 1
From: ex UK [SE], now Sunshine State [QLD,AUS]
Default

Thanks Guys, I shall try those today.
Reply
Old Oct 27, 2004 | 04:20 AM
  #5  
velohead66's Avatar
velohead66
Thread Starter
Scooby Regular
 
Joined: Oct 2002
Posts: 565
Likes: 1
From: ex UK [SE], now Sunshine State [QLD,AUS]
Question

Works very well, very slick !! Thanks.

Thinking laterally now, say I have a cell with a full name in the following syntax [firstname lastname], ie with a space as the separator,
can I use VB (or excel) to separate names.

ie paste firstname into row B
paste surname into row C

The crux is that there maybe between 3 to 12 characters for the firstname and surnames, or any combination thereoff.

Any Thoughts ??
Reply
Old Oct 27, 2004 | 04:48 AM
  #6  
markr1963's Avatar
markr1963
Scooby Regular
 
Joined: Jun 2002
Posts: 1,866
Likes: 0
From: Perth, Western Australia
Default

You could use something like this: [firstname] [lastname] in A1
in B1: = LEFT(A1, FIND(" ",A1,1) ------ finds the space and takes everthing to the left
in C1: = RIGHT(A1, LEN(A1)-FIND(" ",A1,1)) ----- finds the space and takes it's location away from the length of A1

HTH

Mark

Last edited by markr1963; Oct 27, 2004 at 04:50 AM.
Reply
Old Oct 27, 2004 | 08:44 PM
  #7  
velohead66's Avatar
velohead66
Thread Starter
Scooby Regular
 
Joined: Oct 2002
Posts: 565
Likes: 1
From: ex UK [SE], now Sunshine State [QLD,AUS]
Question

This works very nicely, too.
I think I need to learn about the 'find' command in excel, I've never used it til now.

So if I wanted to do exactly the same operations but using VB for excel, would the syntax be slightly different ?
Reply
Old Oct 28, 2004 | 02:40 AM
  #8  
markr1963's Avatar
markr1963
Scooby Regular
 
Joined: Jun 2002
Posts: 1,866
Likes: 0
From: Perth, Western Australia
Default

Syntax is a bit different mainly 'cos of InStr instead of FIND

Dim strName As String

Range("A1").Select
strName = Range("A1").Value


Cells(1, 2) = Left(strName, InStr(1, strName, " ") - 1)
Cells(1, 3) = Right(strName, Len(strName) - InStr(1, strName, " "))


This can, of course, be modified to suit your needs

HTH
Mark
Reply
Related Topics
Thread
Thread Starter
Forum
Replies
Last Post
JimBowen
ICE
5
Jul 2, 2023 01:54 PM
just me
Non Scooby Related
26
Jan 3, 2020 11:12 AM
Mattybr5@MB Developments
Full Cars Breaking For Spares
28
Dec 28, 2015 11:07 PM
Frizzle-Dee
Essex Subaru Owners Club
13
Dec 1, 2015 09:37 AM
S600HBY
Subaru Parts
0
Sep 25, 2015 09:46 AM




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