home hardware prices news articles forums photos user reviews
Go Back   Tech Support Forums - TechIMO.com > PC Hardware and Tech > Webmastering and Programming
Ask a Tech Support Question (free)!

Excel vb macro....

Reply
Get bargains at  »  Dealighted.com
 
Thread Tools Search this Thread
Currently Active Users: 2249
Discussions: 200,937, Posts: 2,379,252, Members: 246,302
Old October 3rd, 2002, 01:58 PM   Digg it!   #1 (permalink)
Junior Member
 
Join Date: Oct 2002
Posts: 6
Excel vb macro....

Hi there,

im creating a macro to change several things in one go in excel, itl have to be done a few hundred time, so a macro is the way to go.

My prob is im a n00b at this (got taught for a year how to program vb, 2 years ago) and was wondering if anyone can help me with something.

Im trying to take a name out of a short list, cut and paste jobby, prob is theres 2 of these in each cell (i.e First Name xxxx Last Name xxxx) id like to cut "Last Name xxxx" and paste it to a different cell, but am not sure how to do so, i think its summit like asc(mid asi remember using that for something similar, but as i say, im crap at this :-) telling vb when to start and then STOP copying i dont know how to do.

Cheers in advance
Hive is offline   Reply With Quote
Old October 3rd, 2002, 02:33 PM     #2 (permalink)
Not Really a Member
 
Join Date: Oct 2001
Posts: 25,385
ok So you have "First Name xxxx Last Name xxxx" in each cell and you want to strip out the xxxx xxxx from first name and last name?

Hmm there anyway you can clean up first name and last name? lol (get rid of the space, just cleaner for a data header)
No worries its all the same

Ok .. the way I would do it..

You can use the InStr function to get the position of a specific text in a given string
DOH.. just realized.. Stupid VBA.. sorry.. VBA uses the FIND function inconsistencies...
The Mid function to actually pull the text from the string.

Dim iLastNamePos As Integer
Dim sFirstName As String
Dim sLastName As String

iLastNamePos = Find("Last Name", CellIndex )

' params
' First = string where our text resides, 2nd where we start, third the number of characters to strip
' here I say the length of the string minus 1 because there is a space between "Last Name" and the first name in the previous part of the string

sFirstName = Mid(CellIndex, 1, iLastNamePos -1)
sLastName = Mid(CellIndex, iLastNamePos, Len(CellIndex) - iLastNamePos)

' Mid(cell, where last name starts, then to the end of the string (len) MINUS the first name stuff, so we use the position of last name)
' Or is this completely off base from what you need?
__________________
Helicopters don't fly; they vibrate so much and make so much noise that the earth rejects them.
vass0922 is offline   Reply With Quote
Old October 3rd, 2002, 02:38 PM     #3 (permalink)
Junior Member
 
Join Date: Oct 2002
Posts: 6
I think thats it cheers, aint got time to check it out cuss i gotta go to work. cheers for the help, ill be back here if i need any more :-D
Hive is offline   Reply With Quote
Old October 3rd, 2002, 08:19 PM     #4 (permalink)
Junior Member
 
Join Date: Oct 2002
Posts: 6
Right, im taking "Last Name xxxxx" out and putting it in another cell, to put it in the other cell i do summit like "Dim sLastNameCell = String" and say sLastNameCell = (sLastname, cellindex)" ???

doesnt look rite to me, but i cant really do much, need a book on this i think :-)
Hive is offline   Reply With Quote
Old October 3rd, 2002, 08:50 PM     #5 (permalink)
Junior Member
 
Join Date: Oct 2002
Posts: 6
er :-)

Is "Cellindex" something like A5, X=1,Y=7 or something else i havnt htought of?
Hive is offline   Reply With Quote
Old October 3rd, 2002, 08:54 PM     #6 (permalink)
Not Really a Member
 
Join Date: Oct 2001
Posts: 25,385
yeah cellindex I can't remember the exact code for it lol sorry
I'm not real strong on excel macros.
You won't be able to use A5 it'll be something like cell.value(a5) or something along those lines
vass0922 is offline   Reply With Quote
Old October 3rd, 2002, 09:40 PM     #7 (permalink)
Junior Member
 
Join Date: Oct 2002
Posts: 6
I messed about with it for an hour, and came across this thing which MIGHT be able to help,


Range("A5").Select
Application.CutCopyMode = True
ActiveCell.FormulaR1C1 = "Last Name Smith"

Only prob is getting it to grab the name as well, as the name changes for each person, something like was said above, that would let me tell it to select Last Name and then the name, however long it is.

Also, i noticed the First name answer is separated from "Last Name" by 3 spaces, could this be used to show where to start the cut from? Something like When ASCII = 3*160 Then CutCopymode = true, thats obviously not it, but something to that effect?

Does my n00bness show thru too much? :-)

Thanks again for the help so far
Hive is offline   Reply With Quote
Old October 4th, 2002, 12:02 AM     #8 (permalink)
Junior Member
 
Join Date: Oct 2002
Posts: 6
it looks like im spamming, but its not intentional, im just kinda excited at doin all this stuff again :-)

ive written some code that i havnt tested (i know it wont work) but id like you to have a look at it anyway, just to tell me what u think :-)

Range("A5").Select
Application.CutCopyMode = xlCut
ActiveCell.FormulaR1C1 = "First Name"
Range("A5").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "Last Name"
Call Finder


End Sub


Sub Finder(ByRef valid As Boolean)
valid = False
firstspace = False
secondspace = False


ix = 1
Do While valid = False
If (Asc(Mid(Cells(5, 3), ix, 1)) = 32) Then
firstspace = True
Else
ix = ix + 1
Loop
End If

If firstspace = True Then
ix = ix + 1
If (Asc(Mid(Cells(5, 3), ix, 1)) = 32) Then
secondspace = True
Else
ix = ix + 1
End If
Loop
End If
If secondspace = True Then
ix = ix + 1
If (Asc(Mid(Cells(5, 3), ix, 1)) = 32) Then
valid = True
Else
ix = ix + 1
Loop
If valid = True Then
Application.CutCopyMode = xlCut
etc :-)

End Sub


Thanks for your patience
Hive is offline   Reply With Quote
Old October 11th, 2002, 04:52 AM     #9 (permalink)
Not Really a Member
 
Join Date: Oct 2001
Posts: 25,385
did you have any luck with this?
sorry forgot to look at it earlier, and too tired now lol

btw if you use the [code] tag it keeps the indenting so its not as ugly
vass0922 is offline   Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Most Active Discussions
Is It Just Me? (2906)
windows 7 problem (7)
CPU fan stops spinning randomly (8)
Wireless Televisions. (8)
California Passes Anti-Flat-HDTV Le.. (43)
Obama the Muslim (14)
Is the PSU I received dead? (11)
windows vista security holes (9)
HIS HD5770 graphic card question (15)
Install XP pro and a Vista laptop ?.. (11)
Print spooler problem (13)
Foreign voltage (10)
Dept. of HS: NSA 'Helped' Develop V.. (15)
A good PSU? (10)
Recent Discussions
windows 7 problem (7)
CPU fan stops spinning randomly (8)
Partition Magic caused HDD problem (3)
Is the PSU I received dead? (11)
Have you switched yet? (85)
Regular Build (4)
Point and Shoot Camera Suggestions. (2)
Modern Warfare 2 freeze (13)
Wireless Televisions. (8)
wireless user (1)
World's largest Monopoly Game using G.. (332)
Ideal cheap graph card for PC-Gaming? (17)
BIOS won't read disk when I try to fl.. (0)
Install XP pro and a Vista laptop ?? (11)
Graphics Card Upgrade Question (1)
favorit (1)
solutions for virtical white lines on.. (1)
Fire in DVD (2)
Modern Warfare For the PC (33)
radeon x850xt platinum & shader 3 (3)
Wireless Router+Cable Modems and Much.. (0)
Optical Audio A-B Switch (1)
windows vista security holes (9)
The NTDVM CPU has encountered an ille.. (24)
[F@H SPAM 11/16/09] ! 1/2 months to r.. (34)


All times are GMT -4. The time now is 12:54 PM.
TechIMO Copyright 2009 All Enthusiast, Inc.



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28