ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Macros (https://www.excelbanter.com/excel-programming/419654-macros.html)

Rob Rudan

Macros
 
I have a list of numbered articles of which the first four digits represents
a unique customer number. I am trying to create a macro to select those first
four digits, copy them and paste them in an adjacent cell.

When I create a macro it seems that whenever it is executed, no matter what
data is in the cell it is trying to extract data from, it always returns the
data obtained when the macro was created. I have tried relative mode as well,
same result. I have also tried incorporating clearing of the clipboard into
the macro, to no avail.

I don't know VBA, but I used to be fair at BASICA. Any suggestions?

FSt1

Macros
 
hi
sounds like you may have done it on record and the data is hard coded into
the code. post your macro.
but as a thought, a formula might do better for you
=left(A1,4)
copy down as far as you need.

Regards
FSt1

"Rob Rudan" wrote:

I have a list of numbered articles of which the first four digits represents
a unique customer number. I am trying to create a macro to select those first
four digits, copy them and paste them in an adjacent cell.

When I create a macro it seems that whenever it is executed, no matter what
data is in the cell it is trying to extract data from, it always returns the
data obtained when the macro was created. I have tried relative mode as well,
same result. I have also tried incorporating clearing of the clipboard into
the macro, to no avail.

I don't know VBA, but I used to be fair at BASICA. Any suggestions?


Rob Rudan

Macros
 
Here is the code for the macro. The formula solution did work by the way.
Thanks very much for your help!

Sub cusnum()
'
' cusnum Macro
' Macro recorded 11/6/2008 by rrudan
'
' Keyboard Shortcut: Ctrl+q
'
Range("B2").Select
ActiveSheet.Paste
Range("B3").Select
End Sub


"FSt1" wrote:

hi
sounds like you may have done it on record and the data is hard coded into
the code. post your macro.
but as a thought, a formula might do better for you
=left(A1,4)
copy down as far as you need.

Regards
FSt1

"Rob Rudan" wrote:

I have a list of numbered articles of which the first four digits represents
a unique customer number. I am trying to create a macro to select those first
four digits, copy them and paste them in an adjacent cell.

When I create a macro it seems that whenever it is executed, no matter what
data is in the cell it is trying to extract data from, it always returns the
data obtained when the macro was created. I have tried relative mode as well,
same result. I have also tried incorporating clearing of the clipboard into
the macro, to no avail.

I don't know VBA, but I used to be fair at BASICA. Any suggestions?


FSt1

Macros
 
hi
you code does paste someting but doesn't give any indication as to what.
if the formula worked , i would stick with that. sometimes the easy way is
the easiest way.

Regards
FSt1

"Rob Rudan" wrote:

Here is the code for the macro. The formula solution did work by the way.
Thanks very much for your help!

Sub cusnum()
'
' cusnum Macro
' Macro recorded 11/6/2008 by rrudan
'
' Keyboard Shortcut: Ctrl+q
'
Range("B2").Select
ActiveSheet.Paste
Range("B3").Select
End Sub


"FSt1" wrote:

hi
sounds like you may have done it on record and the data is hard coded into
the code. post your macro.
but as a thought, a formula might do better for you
=left(A1,4)
copy down as far as you need.

Regards
FSt1

"Rob Rudan" wrote:

I have a list of numbered articles of which the first four digits represents
a unique customer number. I am trying to create a macro to select those first
four digits, copy them and paste them in an adjacent cell.

When I create a macro it seems that whenever it is executed, no matter what
data is in the cell it is trying to extract data from, it always returns the
data obtained when the macro was created. I have tried relative mode as well,
same result. I have also tried incorporating clearing of the clipboard into
the macro, to no avail.

I don't know VBA, but I used to be fair at BASICA. Any suggestions?


FSt1

Macros
 
hi
but here a macro anyway.....
Sub Robsfirstfour()
Dim r As Range
Dim lr As Long
lr = Cells(Rows.Count, "A").End(xlUp).Row
Set r = Range("A2:A" & lr)
For Each cell In r
cell.Offset(0, 1).Value = Left(cell, 4)
Next cell
MsgBox "Done"
End Sub

regards
FSt1

"FSt1" wrote:

hi
you code does paste someting but doesn't give any indication as to what.
if the formula worked , i would stick with that. sometimes the easy way is
the easiest way.

Regards
FSt1

"Rob Rudan" wrote:

Here is the code for the macro. The formula solution did work by the way.
Thanks very much for your help!

Sub cusnum()
'
' cusnum Macro
' Macro recorded 11/6/2008 by rrudan
'
' Keyboard Shortcut: Ctrl+q
'
Range("B2").Select
ActiveSheet.Paste
Range("B3").Select
End Sub


"FSt1" wrote:

hi
sounds like you may have done it on record and the data is hard coded into
the code. post your macro.
but as a thought, a formula might do better for you
=left(A1,4)
copy down as far as you need.

Regards
FSt1

"Rob Rudan" wrote:

I have a list of numbered articles of which the first four digits represents
a unique customer number. I am trying to create a macro to select those first
four digits, copy them and paste them in an adjacent cell.

When I create a macro it seems that whenever it is executed, no matter what
data is in the cell it is trying to extract data from, it always returns the
data obtained when the macro was created. I have tried relative mode as well,
same result. I have also tried incorporating clearing of the clipboard into
the macro, to no avail.

I don't know VBA, but I used to be fair at BASICA. Any suggestions?



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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com