Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

Coding Forum


You are currently viewing our Coding Forum as a guest. Please register to participate.
Login



Reply
Microsoft Excel Macro...
Old 08-19-2006, 08:20 PM Microsoft Excel Macro...
Brian07002's Avatar
Defies a Status

Posts: 2,140
Name: ...
Location: ...
Trades: 0
Can someone help me out here with a simple macro?

I am trying to code a macro inside MS-Excel 2003 to delete these: [Left and Right] brackets and anything inside them.

Thank you guys!
-Brian
__________________
Made2Own

Please login or register to view this content. Registration is FREE
Brian07002 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 08-20-2006, 05:44 AM Re: Microsoft Excel Macro...
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Code:
Sub delSquareBKT()
Dim locStart, locEnd As Integer
Dim strLeft, strRight As String

If InStr(ActiveCell.Text, "[") <> 0 And InStr(ActiveCell.Text, "]") <> 0 Then
locStart = InStr(1, ActiveCell.Text, "[", vbTextCompare)
locEnd = InStr(1, ActiveCell.Text, "]", vbTextCompare)
   strLeft = Left(ActiveCell.Text, locStart - 1)
   strRight = Right(ActiveCell.Text, Len(ActiveCell.Text) - locEnd)
ActiveCell.Value = strLeft & strRight
End If
End Sub
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 08-20-2006, 07:29 PM Re: Microsoft Excel Macro...
Banned

Posts: 61
Name: Oh, don't go there
Location: United States
Trades: 0
Thanks alot!

Only one prob. it's not working with multiple cells selected, I select only one cell at a time, and no problem it works, but if i select all cells that i need to run the macro on, it don't want to work.
Frostydasnowman is offline
Reply With Quote
View Public Profile Visit Frostydasnowman's homepage!
 
Old 08-20-2006, 11:14 PM Re: Microsoft Excel Macro...
ablaye's Avatar
Ultra Talker

Posts: 437
Location: WebmasterGround.com
Trades: 5
You can try recording a macro and performing the actions that you want.
It will all be recording and then you can look at the VB code and make any additions/modification.
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
ablaye is offline
Reply With Quote
View Public Profile Visit ablaye's homepage!
 
Old 08-21-2006, 06:47 AM Re: Microsoft Excel Macro...
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Quote:
Originally Posted by Frostydasnowman View Post
Thanks alot!

Only one prob. it's not working with multiple cells selected, I select only one cell at a time, and no problem it works, but if i select all cells that i need to run the macro on, it don't want to work.
Correct.
It's only written to work on the contents of the active cell. To work on a selected range it would need to loop and move to each cell in the group.

Would the selection be in rows, columns or both ?
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 08-22-2006, 08:53 PM Re: Microsoft Excel Macro...
Banned

Posts: 61
Name: Oh, don't go there
Location: United States
Trades: 0
Quote:
Correct.
It's only written to work on the contents of the active cell. To work on a selected range it would need to loop and move to each cell in the group.

Would the selection be in rows, columns or both ?
I need it to work in columns (going straight dow ex: all records in column A (A1 to A500 for example)) not rows going across.

Thank you Chrishirst!
Frostydasnowman is offline
Reply With Quote
View Public Profile Visit Frostydasnowman's homepage!
 
Old 08-23-2006, 07:04 AM Re: Microsoft Excel Macro...
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
No problem.

recursive subroutines needed in that case.

Code:
Sub delSquareBKT()
Dim locStart, locEnd As Integer
Dim strLeft, strRight As String

If InStr(ActiveCell.Text, "[") <> 0 And InStr(ActiveCell.Text, "]") <> 0 Then
locStart = InStr(1, ActiveCell.Text, "[", vbTextCompare)
locEnd = InStr(1, ActiveCell.Text, "]", vbTextCompare)
   strLeft = Left(ActiveCell.Text, locStart - 1)
   strRight = Right(ActiveCell.Text, Len(ActiveCell.Text) - locEnd)
ActiveCell.Value = strLeft & strRight
End If
moveNext
End Sub

Sub moveNext()
If ActiveCell.Text <> "" Then
    Selection.Offset(1, 0).Activate
    delSquareBKT
End If
End Sub
select the topmost cell and call the delSquareBKT sub, it will then run down the column until it finds an empty cell, where it will end.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 08-23-2006, 07:26 PM Re: Microsoft Excel Macro...
Banned

Posts: 61
Name: Oh, don't go there
Location: United States
Trades: 0
Hi Chrishirst,

The macro does work this time only that it stops unexpectedly with the following error:

Quote:
Error 28: Out of Stack Space
You can see this page for a fix, I can't seem to figure it out

Thanks in advance!
Frostydasnowman is offline
Reply With Quote
View Public Profile Visit Frostydasnowman's homepage!
 
Old 08-23-2006, 08:13 PM Re: Microsoft Excel Macro...
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
It will be too many recursive calls

I tested it on 1500 cells on Excel 2000 and it ran ok, how many cells are in the column you are running it against?

a bit of tweaking to remove the recursion should fix it though.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 08-23-2006, 08:27 PM Re: Microsoft Excel Macro...
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Code:
Sub delSquareBKT()
Dim locStart, locEnd As Integer
Dim strLeft, strRight As String

While ActiveCell.Text <> ""
If InStr(ActiveCell.Text, "[") <> 0 And InStr(ActiveCell.Text, "]") <> 0 Then
locStart = InStr(1, ActiveCell.Text, "[", vbTextCompare)
locEnd = InStr(1, ActiveCell.Text, "]", vbTextCompare)
   strLeft = Left(ActiveCell.Text, locStart - 1)
   strRight = Right(ActiveCell.Text, Len(ActiveCell.Text) - locEnd)
ActiveCell.Value = strLeft & strRight
End If
Selection.Offset(1, 0).Activate
Wend

End Sub
single sub with a while/wend loop, ran on 9000 + cells with no bother.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 09-06-2006, 07:28 PM Re: Microsoft Excel Macro...
Junior Talker

Posts: 1
Trades: 0
You can perform this task with a simple find and replace.

Just put [*] as the find text and leave the replace text empty.

A macro for it looks like the following:

Selection.Replace What:="[*]", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
markusbrainus is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Microsoft Excel Macro...
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.32362 seconds with 12 queries