Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Run Macro through an entire range

I have recorded a macro that reformats a social security number, but I
have only performed the function on one row. How do I edit the macro
to run through all rows that are not blank? Here is the code I have so
far:

Columns("B:G").Select
Selection.Insert Shift:=xlToRight
Range("B2").Select
ActiveCell.FormulaR1C1 = "=LEFT(RC[-1],3)"
Range("C2").Select
ActiveCell.FormulaR1C1 = "=RIGHT(RC[-2],7)"
Range("D2").Select
ActiveCell.FormulaR1C1 = "=LEFT(RC[-1],2)"
Range("E2").Select
ActiveCell.FormulaR1C1 = "=RIGHT(RC[-4],4)"
Range("F2").Select
ActiveCell.FormulaR1C1 = "=CONCATENATE(RC[-4],RC[-2],RC[-1])"
Range("G2").Select
ActiveCell.FormulaR1C1 = "=RC[-1]+0"
Range("G2").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Selection.NumberFormat = "000-00-0000"
Columns("B:F").Select
Selection.Delete Shift:=xlToLeft

I want to be able to run the macro for an entire worksheet, but right
now it only runs on the first row. Anyone have any help?

Thanks

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 486
Default Run Macro through an entire range

Your macro is a bit cumbersome and could probably be lot shorter and more
efficient. What do the Values in Column A Look like (I am guessing
12345?6789)? Let me know that and I can make you something a bit more compact
and efficient...
--
HTH...

Jim Thomlinson


" wrote:

I have recorded a macro that reformats a social security number, but I
have only performed the function on one row. How do I edit the macro
to run through all rows that are not blank? Here is the code I have so
far:

Columns("B:G").Select
Selection.Insert Shift:=xlToRight
Range("B2").Select
ActiveCell.FormulaR1C1 = "=LEFT(RC[-1],3)"
Range("C2").Select
ActiveCell.FormulaR1C1 = "=RIGHT(RC[-2],7)"
Range("D2").Select
ActiveCell.FormulaR1C1 = "=LEFT(RC[-1],2)"
Range("E2").Select
ActiveCell.FormulaR1C1 = "=RIGHT(RC[-4],4)"
Range("F2").Select
ActiveCell.FormulaR1C1 = "=CONCATENATE(RC[-4],RC[-2],RC[-1])"
Range("G2").Select
ActiveCell.FormulaR1C1 = "=RC[-1]+0"
Range("G2").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Selection.NumberFormat = "000-00-0000"
Columns("B:F").Select
Selection.Delete Shift:=xlToLeft

I want to be able to run the macro for an entire worksheet, but right
now it only runs on the first row. Anyone have any help?

Thanks


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,339
Default Run Macro through an entire range

Hi,
Something along these lines but as per Jim's reply, it depends on
the format of the field you are tranforming.

Sub Reformat_SSN()
Dim lastrow As Long, r As Long
lastrow = Cells(Rows.Count, "A").End(xlUp).Row
For r = 2 To lastrow
Cells(r, 2) = Format(Left(Cells(r, 1), 3) & Left(Right(Cells(r, 1), 7),
2) & _
Right(Cells(r, 1), 4), "000-00-0000")
Next r
End Sub

"Jim Thomlinson" wrote:

Your macro is a bit cumbersome and could probably be lot shorter and more
efficient. What do the Values in Column A Look like (I am guessing
12345?6789)? Let me know that and I can make you something a bit more compact
and efficient...
--
HTH...

Jim Thomlinson


" wrote:

I have recorded a macro that reformats a social security number, but I
have only performed the function on one row. How do I edit the macro
to run through all rows that are not blank? Here is the code I have so
far:

Columns("B:G").Select
Selection.Insert Shift:=xlToRight
Range("B2").Select
ActiveCell.FormulaR1C1 = "=LEFT(RC[-1],3)"
Range("C2").Select
ActiveCell.FormulaR1C1 = "=RIGHT(RC[-2],7)"
Range("D2").Select
ActiveCell.FormulaR1C1 = "=LEFT(RC[-1],2)"
Range("E2").Select
ActiveCell.FormulaR1C1 = "=RIGHT(RC[-4],4)"
Range("F2").Select
ActiveCell.FormulaR1C1 = "=CONCATENATE(RC[-4],RC[-2],RC[-1])"
Range("G2").Select
ActiveCell.FormulaR1C1 = "=RC[-1]+0"
Range("G2").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Selection.NumberFormat = "000-00-0000"
Columns("B:F").Select
Selection.Delete Shift:=xlToLeft

I want to be able to run the macro for an entire worksheet, but right
now it only runs on the first row. Anyone have any help?

Thanks


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
When entering data into a range of cells, select the entire range. Q Excel Discussion (Misc queries) 0 September 26th 07 04:36 AM
Macro to print a selected range, not entire worksheet James C Excel Discussion (Misc queries) 3 October 19th 05 10:12 PM
Reading Entire Range Peter[_46_] Excel Programming 1 September 17th 04 04:20 PM
macro to delete entire rows when column A is blank ...a quick macro vikram Excel Programming 4 May 3rd 04 08:45 PM
how do i set an entire row or column to a range? strataguru[_13_] Excel Programming 7 December 25th 03 04:08 AM


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