PC Review


Reply
Thread Tools Rate Thread

Beginner macro programming question

 
 
=?Utf-8?B?aGlnaGxhbmQ=?=
Guest
Posts: n/a
 
      17th Nov 2007
Hi, I want to automate a simple task but know nothing about Excel macro
programming. The macro recorder doesn't do what I want so I guess I need to
write something.

I'd like to perform the following steps in a macro:

1. Cut the contents of the current cell
2. Move over 3 columns to the right
3. Paste the cut data.
4. Move back over to the original position and 1 row down.

That's it. I know, too easy? But I have no idea where to start. If
someone can get me started I can take it from there for the rest of my macro
needs.

Thanks for any help

Steve
 
Reply With Quote
 
 
 
 
=?Utf-8?B?R2FyeScncyBTdHVkZW50?=
Guest
Posts: n/a
 
      17th Nov 2007
How about:

Sub steve2()
With ActiveCell
.Copy .Offset(0, 3)
.Clear
.Offset(1, 0).Select
End With
End Sub
--
Gary''s Student - gsnu200757


"highland" wrote:

> Hi, I want to automate a simple task but know nothing about Excel macro
> programming. The macro recorder doesn't do what I want so I guess I need to
> write something.
>
> I'd like to perform the following steps in a macro:
>
> 1. Cut the contents of the current cell
> 2. Move over 3 columns to the right
> 3. Paste the cut data.
> 4. Move back over to the original position and 1 row down.
>
> That's it. I know, too easy? But I have no idea where to start. If
> someone can get me started I can take it from there for the rest of my macro
> needs.
>
> Thanks for any help
>
> Steve

 
Reply With Quote
 
=?Utf-8?B?T3NzaWVNYWM=?=
Guest
Posts: n/a
 
      17th Nov 2007
Hi Steve,

ActiveCell.Cut
ActiveCell.Offset(0, 3).Select
ActiveSheet.Paste
ActiveCell.Offset(1, -3).Select

--
Regards,

OssieMac


"highland" wrote:

> Hi, I want to automate a simple task but know nothing about Excel macro
> programming. The macro recorder doesn't do what I want so I guess I need to
> write something.
>
> I'd like to perform the following steps in a macro:
>
> 1. Cut the contents of the current cell
> 2. Move over 3 columns to the right
> 3. Paste the cut data.
> 4. Move back over to the original position and 1 row down.
>
> That's it. I know, too easy? But I have no idea where to start. If
> someone can get me started I can take it from there for the rest of my macro
> needs.
>
> Thanks for any help
>
> Steve

 
Reply With Quote
 
=?Utf-8?B?aGlnaGxhbmQ=?=
Guest
Posts: n/a
 
      17th Nov 2007
Perfect! Thanks.

Side note.. why can't I replace the ".Copy" with ".Cut", thereby removing
the requirement to also perform the ".Clear"?

I tried it and it have no idea what it really did... it definitely didn't
work though :-)

"Gary''s Student" wrote:

> How about:
>
> Sub steve2()
> With ActiveCell
> .Copy .Offset(0, 3)
> .Clear
> .Offset(1, 0).Select
> End With
> End Sub
> --
> Gary''s Student - gsnu200757
>
>
> "highland" wrote:
>
> > Hi, I want to automate a simple task but know nothing about Excel macro
> > programming. The macro recorder doesn't do what I want so I guess I need to
> > write something.
> >
> > I'd like to perform the following steps in a macro:
> >
> > 1. Cut the contents of the current cell
> > 2. Move over 3 columns to the right
> > 3. Paste the cut data.
> > 4. Move back over to the original position and 1 row down.
> >
> > That's it. I know, too easy? But I have no idea where to start. If
> > someone can get me started I can take it from there for the rest of my macro
> > needs.
> >
> > Thanks for any help
> >
> > Steve

 
Reply With Quote
 
=?Utf-8?B?R2FyeScncyBTdHVkZW50?=
Guest
Posts: n/a
 
      17th Nov 2007
Actually you can use Cut. For example:

Sub steve()
ActiveCell.Cut
ActiveCell.Offset(0, 3).Select
ActiveSheet.Paste
ActiveCell.Offset(1, -3).Select
End Sub

will do the same thing. This version requires 2 Selects - one to go to the
paste cell and one to get back. Rumor has it that Selects make macros slow.
I don't think it really matters here. Either code will do.
--
Gary''s Student - gsnu200757


"highland" wrote:

> Perfect! Thanks.
>
> Side note.. why can't I replace the ".Copy" with ".Cut", thereby removing
> the requirement to also perform the ".Clear"?
>
> I tried it and it have no idea what it really did... it definitely didn't
> work though :-)
>
> "Gary''s Student" wrote:
>
> > How about:
> >
> > Sub steve2()
> > With ActiveCell
> > .Copy .Offset(0, 3)
> > .Clear
> > .Offset(1, 0).Select
> > End With
> > End Sub
> > --
> > Gary''s Student - gsnu200757
> >
> >
> > "highland" wrote:
> >
> > > Hi, I want to automate a simple task but know nothing about Excel macro
> > > programming. The macro recorder doesn't do what I want so I guess I need to
> > > write something.
> > >
> > > I'd like to perform the following steps in a macro:
> > >
> > > 1. Cut the contents of the current cell
> > > 2. Move over 3 columns to the right
> > > 3. Paste the cut data.
> > > 4. Move back over to the original position and 1 row down.
> > >
> > > That's it. I know, too easy? But I have no idea where to start. If
> > > someone can get me started I can take it from there for the rest of my macro
> > > needs.
> > >
> > > Thanks for any help
> > >
> > > Steve

 
Reply With Quote
 
Gary Keramidas
Guest
Posts: n/a
 
      18th Nov 2007
another way:
should be able to do it with 2 lines of code

ActiveCell.Cut Destination:=ActiveCell.Offset(0, 3)
ActiveCell.Offset(1).Select

--


Gary


"highland" <(E-Mail Removed)> wrote in message
news:411E233A-51A5-44F6-A903-(E-Mail Removed)...
> Hi, I want to automate a simple task but know nothing about Excel macro
> programming. The macro recorder doesn't do what I want so I guess I need to
> write something.
>
> I'd like to perform the following steps in a macro:
>
> 1. Cut the contents of the current cell
> 2. Move over 3 columns to the right
> 3. Paste the cut data.
> 4. Move back over to the original position and 1 row down.
>
> That's it. I know, too easy? But I have no idea where to start. If
> someone can get me started I can take it from there for the rest of my macro
> needs.
>
> Thanks for any help
>
> Steve



 
Reply With Quote
 
=?Utf-8?B?ZnJhbmNpeg==?=
Guest
Posts: n/a
 
      20th Nov 2007
Hi all,

Using the ActiveCell method will mean that your starting cell need to be in
the current cell position where the data is, what if I want to move the data
but I am
not in my starting cell position.

I think we can use the Range method but not sure how to write the codes
Thanks



"Gary''s Student" wrote:

> Actually you can use Cut. For example:
>
> Sub steve()
> ActiveCell.Cut
> ActiveCell.Offset(0, 3).Select
> ActiveSheet.Paste
> ActiveCell.Offset(1, -3).Select
> End Sub
>
> will do the same thing. This version requires 2 Selects - one to go to the
> paste cell and one to get back. Rumor has it that Selects make macros slow.
> I don't think it really matters here. Either code will do.
> --
> Gary''s Student - gsnu200757
>
>
> "highland" wrote:
>
> > Perfect! Thanks.
> >
> > Side note.. why can't I replace the ".Copy" with ".Cut", thereby removing
> > the requirement to also perform the ".Clear"?
> >
> > I tried it and it have no idea what it really did... it definitely didn't
> > work though :-)
> >
> > "Gary''s Student" wrote:
> >
> > > How about:
> > >
> > > Sub steve2()
> > > With ActiveCell
> > > .Copy .Offset(0, 3)
> > > .Clear
> > > .Offset(1, 0).Select
> > > End With
> > > End Sub
> > > --
> > > Gary''s Student - gsnu200757
> > >
> > >
> > > "highland" wrote:
> > >
> > > > Hi, I want to automate a simple task but know nothing about Excel macro
> > > > programming. The macro recorder doesn't do what I want so I guess I need to
> > > > write something.
> > > >
> > > > I'd like to perform the following steps in a macro:
> > > >
> > > > 1. Cut the contents of the current cell
> > > > 2. Move over 3 columns to the right
> > > > 3. Paste the cut data.
> > > > 4. Move back over to the original position and 1 row down.
> > > >
> > > > That's it. I know, too easy? But I have no idea where to start. If
> > > > someone can get me started I can take it from there for the rest of my macro
> > > > needs.
> > > >
> > > > Thanks for any help
> > > >
> > > > Steve

 
Reply With Quote
 
ilia
Guest
Posts: n/a
 
      20th Nov 2007
Is this what you want? Will cut the first cell in selection,
regardless of active cell, and move it three columns over.


Public Sub myMacro()
With Selection.Cells(1)
.Cut .Offset(0, 3)
End With
End Sub

On Nov 20, 10:02 am, franciz <fran...@discussions.microsoft.com>
wrote:
> Hi all,
>
> Using the ActiveCell method will mean that your starting cell need to be in
> the current cell position where the data is, what if I want to move the data
> but I am
> not in my starting cell position.
>
> I think we can use the Range method but not sure how to write the codes
> Thanks
>
>
>
> "Gary''s Student" wrote:
> > Actually you can use Cut. For example:

>
> > Sub steve()
> > ActiveCell.Cut
> > ActiveCell.Offset(0, 3).Select
> > ActiveSheet.Paste
> > ActiveCell.Offset(1, -3).Select
> > End Sub

>
> > will do the same thing. This version requires 2 Selects - one to go to the
> > paste cell and one to get back. Rumor has it that Selects make macros slow.
> > I don't think it really matters here. Either code will do.
> > --
> > Gary''s Student - gsnu200757

>
> > "highland" wrote:

>
> > > Perfect! Thanks.

>
> > > Side note.. why can't I replace the ".Copy" with ".Cut", thereby removing
> > > the requirement to also perform the ".Clear"?

>
> > > I tried it and it have no idea what it really did... it definitely didn't
> > > work though :-)

>
> > > "Gary''s Student" wrote:

>
> > > > How about:

>
> > > > Sub steve2()
> > > > With ActiveCell
> > > > .Copy .Offset(0, 3)
> > > > .Clear
> > > > .Offset(1, 0).Select
> > > > End With
> > > > End Sub
> > > > --
> > > > Gary''s Student - gsnu200757

>
> > > > "highland" wrote:

>
> > > > > Hi, I want to automate a simple task but know nothing about Excel macro
> > > > > programming. The macro recorder doesn't do what I want so I guess I need to
> > > > > write something.

>
> > > > > I'd like to perform the following steps in a macro:

>
> > > > > 1. Cut the contents of the current cell
> > > > > 2. Move over 3 columns to the right
> > > > > 3. Paste the cut data.
> > > > > 4. Move back over to the original position and 1 row down.

>
> > > > > That's it. I know, too easy? But I have no idea where to start. If
> > > > > someone can get me started I can take it from there for the rest of my macro
> > > > > needs.

>
> > > > > Thanks for any help

>
> > > > > Steve- Hide quoted text -

>
> - Show quoted text -


 
Reply With Quote
 
=?Utf-8?B?ZnJhbmNpeg==?=
Guest
Posts: n/a
 
      21st Nov 2007
Thank for looking into this. I think I didn't made myself clear on this.
Using the code by Gary, it only works if you click on the cell with data,
assuming that I have data in col A,B and C and row 1 and 2. If I have click
on a blank anywhere in the sheet and run this code, its will not work because
I am not in cell A1.

How to re-write this code for its to run if I am anywhere in the sheet but
cell A1


"ilia" wrote:

> Is this what you want? Will cut the first cell in selection,
> regardless of active cell, and move it three columns over.
>
>
> Public Sub myMacro()
> With Selection.Cells(1)
> .Cut .Offset(0, 3)
> End With
> End Sub
>
> On Nov 20, 10:02 am, franciz <fran...@discussions.microsoft.com>
> wrote:
> > Hi all,
> >
> > Using the ActiveCell method will mean that your starting cell need to be in
> > the current cell position where the data is, what if I want to move the data
> > but I am
> > not in my starting cell position.
> >
> > I think we can use the Range method but not sure how to write the codes
> > Thanks
> >
> >
> >
> > "Gary''s Student" wrote:
> > > Actually you can use Cut. For example:

> >
> > > Sub steve()
> > > ActiveCell.Cut
> > > ActiveCell.Offset(0, 3).Select
> > > ActiveSheet.Paste
> > > ActiveCell.Offset(1, -3).Select
> > > End Sub

> >
> > > will do the same thing. This version requires 2 Selects - one to go to the
> > > paste cell and one to get back. Rumor has it that Selects make macros slow.
> > > I don't think it really matters here. Either code will do.
> > > --
> > > Gary''s Student - gsnu200757

> >
> > > "highland" wrote:

> >
> > > > Perfect! Thanks.

> >
> > > > Side note.. why can't I replace the ".Copy" with ".Cut", thereby removing
> > > > the requirement to also perform the ".Clear"?

> >
> > > > I tried it and it have no idea what it really did... it definitely didn't
> > > > work though :-)

> >
> > > > "Gary''s Student" wrote:

> >
> > > > > How about:

> >
> > > > > Sub steve2()
> > > > > With ActiveCell
> > > > > .Copy .Offset(0, 3)
> > > > > .Clear
> > > > > .Offset(1, 0).Select
> > > > > End With
> > > > > End Sub
> > > > > --
> > > > > Gary''s Student - gsnu200757

> >
> > > > > "highland" wrote:

> >
> > > > > > Hi, I want to automate a simple task but know nothing about Excel macro
> > > > > > programming. The macro recorder doesn't do what I want so I guess I need to
> > > > > > write something.

> >
> > > > > > I'd like to perform the following steps in a macro:

> >
> > > > > > 1. Cut the contents of the current cell
> > > > > > 2. Move over 3 columns to the right
> > > > > > 3. Paste the cut data.
> > > > > > 4. Move back over to the original position and 1 row down.

> >
> > > > > > That's it. I know, too easy? But I have no idea where to start. If
> > > > > > someone can get me started I can take it from there for the rest of my macro
> > > > > > needs.

> >
> > > > > > Thanks for any help

> >
> > > > > > Steve- Hide quoted text -

> >
> > - Show quoted text -

>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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 On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel macro programming question Anne Microsoft Excel Programming 8 7th Jul 2009 11:27 PM
Macro Programming Question mtbcpa Microsoft Excel Misc 2 26th Nov 2007 04:51 PM
an outlook2000 macro programming question..... Alont Microsoft Outlook 0 8th Jan 2006 03:14 AM
Beginner programming - #Name? error =?Utf-8?B?UGV0ZXIgSw==?= Microsoft Access VBA Modules 5 12th Jun 2005 06:11 AM
Programming for a beginner Arianrhod Windows XP New Users 3 28th Oct 2004 06:38 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:05 AM.