+ Reply to Thread
Results 1 to 8 of 8

Help with "Do until empty" Loop

  1. #1
    Registered User
    Join Date
    05-14-2013
    Location
    Ottawa
    MS-Off Ver
    Excel 2003
    Posts
    12

    Help with "Do until empty" Loop

    Ok, here it is.

    I need to remove the dashes from a number (cells are formated as "General" because I need the preceding zero's) that is stored in Column B. The first cell containing the data is B2. The numbers found in columns B look like this, 00-838-5033. I need the output to be in Row H, as a value, in "General" format. Blank columns C through H have already been inserted to do the formulas.

    For the loop portion, I need this to run until it reaches a blank cell in column B.

    Here's the code I used (remember that I'm extremely new to this, so probably extremely inefficient in my coding):

    Sub RemoveDash()
    '
    ' RemoveDash Macro
    '
    Range("C2").Select
    ActiveCell.FormulaR1C1 = "=LEFT(RC[-1],LEN(RC[-1])-9)"
    Range("D2").Select
    ActiveCell.FormulaR1C1 = "=LEFT(RC[-2],LEN(RC[-2])-5)"
    Range("E2").Select
    ActiveCell.FormulaR1C1 = "=RIGHT(RC[-1],LEN(RC[-1])-3)"
    Range("F2").Select
    ActiveCell.FormulaR1C1 = "=RIGHT(RC[-4],LEN(RC[-4])-7)"
    Range("G2").Select
    ActiveCell.FormulaR1C1 = "=RC[-4]&RC[-2]&RC[-1]"
    Range("G2").Select
    Selection.Copy
    Range("H2").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    Application.CutCopyMode = False
    End Sub

    Thanks in advance,
    Dave

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Help with "Do until empty" Loop

    Perhaps you could do it without a loop?
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    05-14-2013
    Location
    Ottawa
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Help with "Do until empty" Loop

    Norie,

    Thanks for the quick reply. I've copied and pasted your code into the macro, but I'm getting the followoing error, "Compile error: Invalid use of proptery". The "Sub RemoveDash()" is highlighted in yellow and ".FormulaR1C1 " of the Range("E2:E" & LastRow).FormulaR1C1 "=RIGHT(RC[-1],LEN(RC[-1])-3)" line of code is selected (blue).

    Any ideas????

    Could it be because of the LastRow = Range("B" & Rows.Count).End(xlUp).Row referring to "B"???

    I'm just grasping here!!!
    Last edited by dfurn; 01-14-2015 at 01:39 PM.

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Help with "Do until empty" Loop

    It's a typo.

    Specifically a missing =.
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    05-14-2013
    Location
    Ottawa
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Help with "Do until empty" Loop

    I actually just saw that and was going to let you know, when I got the email stating that you replied. Thanks again.

    The macro now runs with no errors, however, the pasting of resulting value is populated in cells of Column N and starting in cell N3 and finishing one row past the last row with data.

    ??????

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Help with "Do until empty" Loop

    Another 'typo'. well mistake really - I was in a rush, honest.

    Anyway, 3rd time lucky.
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    05-14-2013
    Location
    Ottawa
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Help with "Do until empty" Loop

    Norie,

    Thanks so much for sticking with this. The thrid time was lucky. It works greast.

  8. #8
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Help with "Do until empty" Loop

    No problem.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] How to copy into next empty row using "for each cell in range" loop
    By GIS2013 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-23-2013, 02:30 PM
  2. [SOLVED] "IF" to "IFERROR" (or other formula) help by skipping empty cells
    By slack578 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 08-10-2013, 03:50 PM
  3. transpose loop with "empty cell" condition
    By ana_cociorva in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-12-2011, 04:24 PM
  4. Replies: 4
    Last Post: 02-03-2008, 05:11 PM
  5. Do Loop until empty row (column "A")
    By Jim15 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 08-17-2005, 10:01 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1