ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   macro code shortcut (https://www.excelbanter.com/excel-worksheet-functions/7967-macro-code-shortcut.html)

Brian

macro code shortcut
 
I am using the following code in a macro and the purpose is to have cells in
a column take on the value of the cells in the column beside it...

Private sub
range ("i7:i600").value=Range("h7:h600").value
range ("h7:h600").value=Range("g7:g600").value
range ("g7:g600").value=Range("f7:f600").value
end sub

I want to expand the above macro to do approximately 100 additional columns.
Do I have to write out each line individually or is there a shorter code that
will do this.

Thanks.




Don Guillett

if col g becomes the values of col f, how does now col h become the value
for col g??

--
Don Guillett
SalesAid Software

"Brian" wrote in message
...
I am using the following code in a macro and the purpose is to have cells

in
a column take on the value of the cells in the column beside it...

Private sub
range ("i7:i600").value=Range("h7:h600").value
range ("h7:h600").value=Range("g7:g600").value
range ("g7:g600").value=Range("f7:f600").value
end sub

I want to expand the above macro to do approximately 100 additional

columns.
Do I have to write out each line individually or is there a shorter code

that
will do this.

Thanks.






Brian

The code described below will do this. I am just wondering if there is a
better(shorter) way to write the code to do many more columns. There may not
be a shorter way to write this.

"Don Guillett" wrote:

if col g becomes the values of col f, how does now col h become the value
for col g??

--
Don Guillett
SalesAid Software

"Brian" wrote in message
...
I am using the following code in a macro and the purpose is to have cells

in
a column take on the value of the cells in the column beside it...

Private sub
range ("i7:i600").value=Range("h7:h600").value
range ("h7:h600").value=Range("g7:g600").value
range ("g7:g600").value=Range("f7:f600").value
end sub

I want to expand the above macro to do approximately 100 additional

columns.
Do I have to write out each line individually or is there a shorter code

that
will do this.

Thanks.







Don Guillett

Perhaps you should read my reply again and start over with a more complete
explanation. I'm getting kind of old and don't hear well.

--
Don Guillett
SalesAid Software

"Brian" wrote in message
...
The code described below will do this. I am just wondering if there is a
better(shorter) way to write the code to do many more columns. There may

not
be a shorter way to write this.

"Don Guillett" wrote:

if col g becomes the values of col f, how does now col h become the

value
for col g??

--
Don Guillett
SalesAid Software

"Brian" wrote in message
...
I am using the following code in a macro and the purpose is to have

cells
in
a column take on the value of the cells in the column beside it...

Private sub
range ("i7:i600").value=Range("h7:h600").value
range ("h7:h600").value=Range("g7:g600").value
range ("g7:g600").value=Range("f7:f600").value
end sub

I want to expand the above macro to do approximately 100 additional

columns.
Do I have to write out each line individually or is there a shorter

code
that
will do this.

Thanks.









Art

Try this:

Sub test()
Dim i As Integer
For i = 9 To 7 Step -1
Range(Cells(1, i), Cells(600, i)).Value = _
Range(Cells(1, i - 1), Cells(600, i - 1)).Value
Next i
End Sub

Art


All times are GMT +1. The time now is 06:59 PM.

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