Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Loop to move #'s from one column to next

I have a macro that moves a bunch of columns around, formats them, and
inserts a blank column A. That's the easy part :).

Problem 1: In column A, I want to collect data from column B using
=RIGHT(B1,3). I want this to loop through until there is no more data in
column B (length will always vary).

Problem 2: If the number transfered into column A is 001, or 011, I wan to
loose the zeros. Can't seem to make them disappear with formatting, so I'm
thinking now I need if statements to use +RIGHT(B1,1) or (B1,2) under those
circumstances. But maybe I'm making this too complicated.

Any help would be much appreciated.

Thanks,
Diana
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Loop to move #'s from one column to next

Diana,

This macro takes over from the point where column A is inserted

Sub stitution()
Columns("A:A").Select
Selection.Insert Shift:=xlToRight 'Inserts new column
lastrow = Cells(Cells.Rows.Count, "B").End(xlUp).Row
Set myrange = Range("A1:A" & lastrow)
For Each c In myrange
c.Value = c.Offset(0, 1).Value
Next
End Sub

Mike

"Diana Morrison" wrote:

I have a macro that moves a bunch of columns around, formats them, and
inserts a blank column A. That's the easy part :).

Problem 1: In column A, I want to collect data from column B using
=RIGHT(B1,3). I want this to loop through until there is no more data in
column B (length will always vary).

Problem 2: If the number transfered into column A is 001, or 011, I wan to
loose the zeros. Can't seem to make them disappear with formatting, so I'm
thinking now I need if statements to use +RIGHT(B1,1) or (B1,2) under those
circumstances. But maybe I'm making this too complicated.

Any help would be much appreciated.

Thanks,
Diana

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Loop to move #'s from one column to next

Forgot the maximum length of three bit

c.Value = Right(c.Offset(0, 1).Value, 3)

Use this line instead

Mike

"Mike H" wrote:

Diana,

This macro takes over from the point where column A is inserted

Sub stitution()
Columns("A:A").Select
Selection.Insert Shift:=xlToRight 'Inserts new column
lastrow = Cells(Cells.Rows.Count, "B").End(xlUp).Row
Set myrange = Range("A1:A" & lastrow)
For Each c In myrange
c.Value = c.Offset(0, 1).Value
Next
End Sub

Mike

"Diana Morrison" wrote:

I have a macro that moves a bunch of columns around, formats them, and
inserts a blank column A. That's the easy part :).

Problem 1: In column A, I want to collect data from column B using
=RIGHT(B1,3). I want this to loop through until there is no more data in
column B (length will always vary).

Problem 2: If the number transfered into column A is 001, or 011, I wan to
loose the zeros. Can't seem to make them disappear with formatting, so I'm
thinking now I need if statements to use +RIGHT(B1,1) or (B1,2) under those
circumstances. But maybe I'm making this too complicated.

Any help would be much appreciated.

Thanks,
Diana

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Loop to move #'s from one column to next

I don't know if this is more efficient than your code or not (probably "yes"
if then number of rows is large), but we can eliminate your looping through
each cell in the column by modifying your code like this...

Sub Stitution()
Columns("A:A").Insert Shift:=xlToRight
LastRow = Cells(Cells.Rows.Count, "B").End(xlUp).Row
With Range("B1:B" & LastRow)
.Copy Range("A1")
.NumberFormat = "General"
Cells(LastRow + 1, "B").Value = 1
Cells(LastRow + 1, "B").Copy
.PasteSpecial , xlPasteSpecialOperationMultiply
Cells(LastRow + 1, "B").Clear
End With
End Sub

Rick


"Mike H" wrote in message
...
Forgot the maximum length of three bit

c.Value = Right(c.Offset(0, 1).Value, 3)

Use this line instead

Mike

"Mike H" wrote:

Diana,

This macro takes over from the point where column A is inserted

Sub stitution()
Columns("A:A").Select
Selection.Insert Shift:=xlToRight 'Inserts new column
lastrow = Cells(Cells.Rows.Count, "B").End(xlUp).Row
Set myrange = Range("A1:A" & lastrow)
For Each c In myrange
c.Value = c.Offset(0, 1).Value
Next
End Sub

Mike

"Diana Morrison" wrote:

I have a macro that moves a bunch of columns around, formats them, and
inserts a blank column A. That's the easy part :).

Problem 1: In column A, I want to collect data from column B using
=RIGHT(B1,3). I want this to loop through until there is no more data
in
column B (length will always vary).

Problem 2: If the number transfered into column A is 001, or 011, I
wan to
loose the zeros. Can't seem to make them disappear with formatting, so
I'm
thinking now I need if statements to use +RIGHT(B1,1) or (B1,2) under
those
circumstances. But maybe I'm making this too complicated.

Any help would be much appreciated.

Thanks,
Diana


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Loop to move #'s from one column to next

Rick,

You're correct your modified code is much faster and I considered something
along those lines but couldn't work out a syntax (and still can't) to meet
the OP requirement

Problem 1: In column A, I want to collect data from column B using
=RIGHT(B1,3).


for only taking the 3 righmost digits. I'm sure it's simple but I can't see it

Mike


"Rick Rothstein (MVP - VB)" wrote:

I don't know if this is more efficient than your code or not (probably "yes"
if then number of rows is large), but we can eliminate your looping through
each cell in the column by modifying your code like this...

Sub Stitution()
Columns("A:A").Insert Shift:=xlToRight
LastRow = Cells(Cells.Rows.Count, "B").End(xlUp).Row
With Range("B1:B" & LastRow)
.Copy Range("A1")
.NumberFormat = "General"
Cells(LastRow + 1, "B").Value = 1
Cells(LastRow + 1, "B").Copy
.PasteSpecial , xlPasteSpecialOperationMultiply
Cells(LastRow + 1, "B").Clear
End With
End Sub

Rick


"Mike H" wrote in message
...
Forgot the maximum length of three bit

c.Value = Right(c.Offset(0, 1).Value, 3)

Use this line instead

Mike

"Mike H" wrote:

Diana,

This macro takes over from the point where column A is inserted

Sub stitution()
Columns("A:A").Select
Selection.Insert Shift:=xlToRight 'Inserts new column
lastrow = Cells(Cells.Rows.Count, "B").End(xlUp).Row
Set myrange = Range("A1:A" & lastrow)
For Each c In myrange
c.Value = c.Offset(0, 1).Value
Next
End Sub

Mike

"Diana Morrison" wrote:

I have a macro that moves a bunch of columns around, formats them, and
inserts a blank column A. That's the easy part :).

Problem 1: In column A, I want to collect data from column B using
=RIGHT(B1,3). I want this to loop through until there is no more data
in
column B (length will always vary).

Problem 2: If the number transfered into column A is 001, or 011, I
wan to
loose the zeros. Can't seem to make them disappear with formatting, so
I'm
thinking now I need if statements to use +RIGHT(B1,1) or (B1,2) under
those
circumstances. But maybe I'm making this too complicated.

Any help would be much appreciated.

Thanks,
Diana



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
Make a loop to Find a value then move a row of cells Bill F Excel Programming 1 June 8th 06 08:24 AM
Loop through column headers to search from column name and get cell range Pie Excel Programming 9 December 29th 05 12:17 AM
Move msgbox out of loop Phil Floyd[_2_] Excel Programming 4 March 19th 05 03:08 PM
Loop column A and delete and move on condition Rob Excel Programming 6 January 15th 05 03:14 PM
Macro to move, create formulas and loop NewMacro Excel Programming 5 February 2nd 04 10:12 PM


All times are GMT +1. The time now is 12:38 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"