Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Build a Macro that uses keystrokes

I need to write some macros that are based on keystrokes. I've done it in
other spreadsheets, but can not figure out how to do it in Excel 2003. As an
example, I import delimited files and sometimes they must be edited to format
correctly. If the field has <blank<blank12:30:30, it is viewed as a text
field. To correct this I need to remove the leading blanks. The keystrokes
would be <F2<Home<Del<Del<Enter. This should take me to the next field
and able to repeat the macro. When I record the macro it give me a hard
value of 12:30:30.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 638
Default Build a Macro that uses keystrokes

You do not need to use keystrokes to do what you need. You can use
Trim(ActiveCell.Value), or somethign similar, to get rid of all
unnecessary spaces. ActiveCell wouldn't be my first choice though.
You could use a For Next loop to cycle through the column containing
the screwed up cells. HTH
King Ki wrote:
I need to write some macros that are based on keystrokes. I've done it in
other spreadsheets, but can not figure out how to do it in Excel 2003. As an
example, I import delimited files and sometimes they must be edited to format
correctly. If the field has <blank<blank12:30:30, it is viewed as a text
field. To correct this I need to remove the leading blanks. The keystrokes
would be <F2<Home<Del<Del<Enter. This should take me to the next field
and able to repeat the macro. When I record the macro it give me a hard
value of 12:30:30.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Build a Macro that uses keystrokes

In this case, you are correct. However I still have other issues that I
would like to build macros based on keystrokes

Thanks

"JW" wrote:

You do not need to use keystrokes to do what you need. You can use
Trim(ActiveCell.Value), or somethign similar, to get rid of all
unnecessary spaces. ActiveCell wouldn't be my first choice though.
You could use a For Next loop to cycle through the column containing
the screwed up cells. HTH
King Ki wrote:
I need to write some macros that are based on keystrokes. I've done it in
other spreadsheets, but can not figure out how to do it in Excel 2003. As an
example, I import delimited files and sometimes they must be edited to format
correctly. If the field has <blank<blank12:30:30, it is viewed as a text
field. To correct this I need to remove the leading blanks. The keystrokes
would be <F2<Home<Del<Del<Enter. This should take me to the next field
and able to repeat the macro. When I record the macro it give me a hard
value of 12:30:30.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 638
Default Build a Macro that uses keystrokes

In that case, have a look at the SendKeys method in VBA. This would
do what you want, but you have to be in teh Excel window when you run
it, not the VBA window. If you are in the VBA window, it will apply
the changes to whatever line you are on in the VBE.
Application.SendKeys ("{F2}{HOME}{DEL}{DEL}~")
King Ki wrote:
In this case, you are correct. However I still have other issues that I
would like to build macros based on keystrokes

Thanks

"JW" wrote:

You do not need to use keystrokes to do what you need. You can use
Trim(ActiveCell.Value), or somethign similar, to get rid of all
unnecessary spaces. ActiveCell wouldn't be my first choice though.
You could use a For Next loop to cycle through the column containing
the screwed up cells. HTH
King Ki wrote:
I need to write some macros that are based on keystrokes. I've done it in
other spreadsheets, but can not figure out how to do it in Excel 2003. As an
example, I import delimited files and sometimes they must be edited to format
correctly. If the field has <blank<blank12:30:30, it is viewed as a text
field. To correct this I need to remove the leading blanks. The keystrokes
would be <F2<Home<Del<Del<Enter. This should take me to the next field
and able to repeat the macro. When I record the macro it give me a hard
value of 12:30:30.




  #5   Report Post  
Posted to microsoft.public.excel.programming
JNW JNW is offline
external usenet poster
 
Posts: 480
Default Build a Macro that uses keystrokes

the macro recorder doesn't recognize keystrokes once you enter edit mode in a
cell. As soon as you press F2 the only thing the recorder will see is the
value or formula in the cell when you leave edit mode.

So to answer your question. If your keystrokes always involve doing things
in edit mode inside cells, then no, you can't record them.

This being said, there are other ways to go about doing things. JW gave you
the work around for the example you gave. There is generally a way to do
something, even if it takes some inventive code.
--
JNW


"King Ki" wrote:

In this case, you are correct. However I still have other issues that I
would like to build macros based on keystrokes

Thanks

"JW" wrote:

You do not need to use keystrokes to do what you need. You can use
Trim(ActiveCell.Value), or somethign similar, to get rid of all
unnecessary spaces. ActiveCell wouldn't be my first choice though.
You could use a For Next loop to cycle through the column containing
the screwed up cells. HTH
King Ki wrote:
I need to write some macros that are based on keystrokes. I've done it in
other spreadsheets, but can not figure out how to do it in Excel 2003. As an
example, I import delimited files and sometimes they must be edited to format
correctly. If the field has <blank<blank12:30:30, it is viewed as a text
field. To correct this I need to remove the leading blanks. The keystrokes
would be <F2<Home<Del<Del<Enter. This should take me to the next field
and able to repeat the macro. When I record the macro it give me a hard
value of 12:30:30.





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Build a Macro that uses keystrokes

If I can't record them can I go into VB and Edit them?

"JNW" wrote:

the macro recorder doesn't recognize keystrokes once you enter edit mode in a
cell. As soon as you press F2 the only thing the recorder will see is the
value or formula in the cell when you leave edit mode.

So to answer your question. If your keystrokes always involve doing things
in edit mode inside cells, then no, you can't record them.

This being said, there are other ways to go about doing things. JW gave you
the work around for the example you gave. There is generally a way to do
something, even if it takes some inventive code.
--
JNW


"King Ki" wrote:

In this case, you are correct. However I still have other issues that I
would like to build macros based on keystrokes

Thanks

"JW" wrote:

You do not need to use keystrokes to do what you need. You can use
Trim(ActiveCell.Value), or somethign similar, to get rid of all
unnecessary spaces. ActiveCell wouldn't be my first choice though.
You could use a For Next loop to cycle through the column containing
the screwed up cells. HTH
King Ki wrote:
I need to write some macros that are based on keystrokes. I've done it in
other spreadsheets, but can not figure out how to do it in Excel 2003. As an
example, I import delimited files and sometimes they must be edited to format
correctly. If the field has <blank<blank12:30:30, it is viewed as a text
field. To correct this I need to remove the leading blanks. The keystrokes
would be <F2<Home<Del<Del<Enter. This should take me to the next field
and able to repeat the macro. When I record the macro it give me a hard
value of 12:30:30.


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Build a Macro that uses keystrokes

Yes.

You don't have to ever record a macro - it is just useful at times.

In the VBE, Insert=Module

type in the code you want.

--
Regards,
Tom Ogilvy


"King Ki" wrote:

If I can't record them can I go into VB and Edit them?

"JNW" wrote:

the macro recorder doesn't recognize keystrokes once you enter edit mode in a
cell. As soon as you press F2 the only thing the recorder will see is the
value or formula in the cell when you leave edit mode.

So to answer your question. If your keystrokes always involve doing things
in edit mode inside cells, then no, you can't record them.

This being said, there are other ways to go about doing things. JW gave you
the work around for the example you gave. There is generally a way to do
something, even if it takes some inventive code.
--
JNW


"King Ki" wrote:

In this case, you are correct. However I still have other issues that I
would like to build macros based on keystrokes

Thanks

"JW" wrote:

You do not need to use keystrokes to do what you need. You can use
Trim(ActiveCell.Value), or somethign similar, to get rid of all
unnecessary spaces. ActiveCell wouldn't be my first choice though.
You could use a For Next loop to cycle through the column containing
the screwed up cells. HTH
King Ki wrote:
I need to write some macros that are based on keystrokes. I've done it in
other spreadsheets, but can not figure out how to do it in Excel 2003. As an
example, I import delimited files and sometimes they must be edited to format
correctly. If the field has <blank<blank12:30:30, it is viewed as a text
field. To correct this I need to remove the leading blanks. The keystrokes
would be <F2<Home<Del<Del<Enter. This should take me to the next field
and able to repeat the macro. When I record the macro it give me a hard
value of 12:30:30.


  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 638
Default Build a Macro that uses keystrokes

Edit them? Not really sure what you mean. You can use SendKeys to do
practically anything, but I don't really condone it. There are
generally other ways to do things. But, if you have to use send keys,
it can most likely be done.
Here is an example of entering a cell and typing "fred".
Application.SendKeys ("{F2}fred")
King Ki wrote:
If I can't record them can I go into VB and Edit them?

"JNW" wrote:

the macro recorder doesn't recognize keystrokes once you enter edit mode in a
cell. As soon as you press F2 the only thing the recorder will see is the
value or formula in the cell when you leave edit mode.

So to answer your question. If your keystrokes always involve doing things
in edit mode inside cells, then no, you can't record them.

This being said, there are other ways to go about doing things. JW gave you
the work around for the example you gave. There is generally a way to do
something, even if it takes some inventive code.
--
JNW


"King Ki" wrote:

In this case, you are correct. However I still have other issues that I
would like to build macros based on keystrokes

Thanks

"JW" wrote:

You do not need to use keystrokes to do what you need. You can use
Trim(ActiveCell.Value), or somethign similar, to get rid of all
unnecessary spaces. ActiveCell wouldn't be my first choice though.
You could use a For Next loop to cycle through the column containing
the screwed up cells. HTH
King Ki wrote:
I need to write some macros that are based on keystrokes. I've done it in
other spreadsheets, but can not figure out how to do it in Excel 2003. As an
example, I import delimited files and sometimes they must be edited to format
correctly. If the field has <blank<blank12:30:30, it is viewed as a text
field. To correct this I need to remove the leading blanks. The keystrokes
would be <F2<Home<Del<Del<Enter. This should take me to the next field
and able to repeat the macro. When I record the macro it give me a hard
value of 12:30:30.



  #9   Report Post  
Posted to microsoft.public.excel.programming
JNW JNW is offline
external usenet poster
 
Posts: 480
Default Build a Macro that uses keystrokes

You can edit any macro in the VB editor, even recorded ones. But if all it
is recording is the value when you exit there won't be much to edit! :-)
--
JNW


"King Ki" wrote:

If I can't record them can I go into VB and Edit them?

"JNW" wrote:

the macro recorder doesn't recognize keystrokes once you enter edit mode in a
cell. As soon as you press F2 the only thing the recorder will see is the
value or formula in the cell when you leave edit mode.

So to answer your question. If your keystrokes always involve doing things
in edit mode inside cells, then no, you can't record them.

This being said, there are other ways to go about doing things. JW gave you
the work around for the example you gave. There is generally a way to do
something, even if it takes some inventive code.
--
JNW


"King Ki" wrote:

In this case, you are correct. However I still have other issues that I
would like to build macros based on keystrokes

Thanks

"JW" wrote:

You do not need to use keystrokes to do what you need. You can use
Trim(ActiveCell.Value), or somethign similar, to get rid of all
unnecessary spaces. ActiveCell wouldn't be my first choice though.
You could use a For Next loop to cycle through the column containing
the screwed up cells. HTH
King Ki wrote:
I need to write some macros that are based on keystrokes. I've done it in
other spreadsheets, but can not figure out how to do it in Excel 2003. As an
example, I import delimited files and sometimes they must be edited to format
correctly. If the field has <blank<blank12:30:30, it is viewed as a text
field. To correct this I need to remove the leading blanks. The keystrokes
would be <F2<Home<Del<Del<Enter. This should take me to the next field
and able to repeat the macro. When I record the macro it give me a hard
value of 12:30:30.


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Recording a Macro that follows Keystrokes freakyquo Excel Discussion (Misc queries) 3 September 6th 07 04:42 PM
Special keystrokes in a Macro Eric Excel Discussion (Misc queries) 4 May 18th 05 02:26 PM
Relative Macro Help on Keystrokes Neal Zimm Excel Discussion (Misc queries) 9 December 15th 04 12:31 AM
How to build build a macro that automatically imports PedroPeso Excel Programming 1 December 26th 03 08:14 PM
Toggle Macro with KeyStrokes Cesar Zapata[_2_] Excel Programming 0 November 13th 03 05:07 PM


All times are GMT +1. The time now is 10:17 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"