+ Reply to Thread
Results 1 to 5 of 5

Do Until with If IsNumeric

Hybrid View

doyoc Do Until with If IsNumeric 04-10-2015, 12:00 PM
JasperD Re: Do Until with If IsNumeric 04-10-2015, 12:17 PM
doyoc Re: Do Until with If IsNumeric 04-10-2015, 12:41 PM
stnkynts Re: Do Until with If IsNumeric 04-10-2015, 04:04 PM
doyoc Re: Do Until with If IsNumeric 04-11-2015, 06:22 AM
  1. #1
    Registered User
    Join Date
    04-09-2015
    Location
    Washington, DC
    MS-Off Ver
    2009
    Posts
    3

    Do Until with If IsNumeric

    Hi all,

    I'm trying to construct a macro to track sales of particular products by week. I have week numbers along the horizontal axis (in Row 4), and product numbers along the vertical axis (in Column A). I would like the macro to find the previous week number on the horizontal axis, and if there is a product number in column A for that row, perform the VLOOKUP. If there is not a product number in that row, I would like to advance to the next cell. This should continue until the "**" at the bottom of the sheet.

    I can find the correct week number on the horizontal axis, but I think my Do loop is wrong - it's just advancing down the column without performing any VLOOKUPS.

    Here's the code I've used:

    Sub Macro1()

    **the first part of the code finds the correct week in Row 4**

    ActiveCell.Offset(2, 0).Activate

    Do Until ActiveCell.Value = "**"
    If IsNumeric(Cells(1, 1)) = True Then
    ActiveCell.Formula = "=VLOOKUP(RC1,'SA021'!C2:C16,15,0)"
    ElseIf IsNumeric(Cells(1, 1)) = False Then
    ActiveCell.Offset(1, 0).Activate
    End If

    Loop

    End Sub


    Any help would be greatly appreciated!
    Attached Images Attached Images
    Attached Files Attached Files
    Last edited by doyoc; 04-10-2015 at 12:40 PM. Reason: attached full spreadsheet

  2. #2
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    Re: Do Until with If IsNumeric

    please share your whole code and/or workbook.

  3. #3
    Registered User
    Join Date
    04-09-2015
    Location
    Washington, DC
    MS-Off Ver
    2009
    Posts
    3

    Re: Do Until with If IsNumeric

    revised post with spreadsheet attached

  4. #4
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Do Until with If IsNumeric

    Sub doyoc()
    Dim ws1 As Worksheet:   Set ws1 = Sheets("RoomTracker")
    Dim ws2 As Worksheet:   Set ws2 = Sheets("SA021")
    Dim rFind As Range, c As Range, rng As Range, numFind As Range
    Dim strErr As String
    
    Application.ScreenUpdating = False
    
    Set rFind = ws1.Rows(4).Find(WorksheetFunction.WeekNum(Date, 1), , xlValues, xlWhole).Offset(, -2)
    Set rng = ws1.Range("A5:A" & ws1.Range("A" & Rows.Count).End(xlUp).Row)
    strErr = vbNullString
    
    If Not rFind Is Nothing Then
        For Each c In rng
            If IsNumeric(c) And Len(c) = 8 Then
                Set numFind = ws2.Range("B2:B" & ws2.Range("B" & Rows.Count).End(xlUp).Row).Find(c, , xlValues, xlWhole)
                    If Not numFind Is Nothing Then
                        ws1.Cells(c.Row, rFind.Column) = ws2.Range("P" & numFind.Row)
                    Else
                        strErr = strErr & Chr(10) & c
                    End If
            End If
        Next c
    Else
        MsgBox ("Error. Could not find week.")
    End If
    
    If Not strErr = vbNullString Then
        MsgBox ("The following numbers could not be found:" & strErr)
    End If
        
    Application.ScreenUpdating = True
    
    End Sub

  5. #5
    Registered User
    Join Date
    04-09-2015
    Location
    Washington, DC
    MS-Off Ver
    2009
    Posts
    3

    Re: Do Until with If IsNumeric

    Thanks so much, sknkynts...works perfectly!

+ 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. Help with IsNumeric Syntax
    By TextMonkey in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-06-2014, 08:30 PM
  2. [SOLVED] IsNumeric Help
    By Brumbot in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-19-2013, 08:29 AM
  3. IsNumeric
    By Risdell in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-18-2010, 03:32 PM
  4. [SOLVED] Isnumeric
    By Richard in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-26-2006, 04:25 PM
  5. help with If Isnumeric
    By justchris in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-03-2005, 12:57 AM

Tags for this Thread

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