+ Reply to Thread
Results 1 to 6 of 6

A maco makes all my Vlookups and formulas disappear!!!!

Hybrid View

  1. #1
    Registered User
    Join Date
    11-06-2015
    Location
    San Diego
    MS-Off Ver
    2013
    Posts
    82

    A maco makes all my Vlookups and formulas disappear!!!!

    Hi guys,
    So I have this macro to multiply all any row in a workbook that has an X in column B by a coefficient I designate. The macro works but when I run it not only does it multiply the rows i want but it also makes all the vlookups and formulas in any other cell that does not have a X in column B disappear and just leaves the most recent number that was in the cell but no formulas or vlookup. How do I stop this from happening I am very confused. Here is the code.
    Thank you everyone,
    Your friend

    Sub test123()
        Dim ws As Worksheet, e, coef, myCurr As String
        For Each e In Array(Array("Euro", "a1"), Array("US Dollar", "b1"))
            If Sheets("Config & Summary").[i2] Like "*" & e(0) & "*" Then
                myCurr = e(0)
                coef = Sheets("currency").Range(e(1))
                Exit For
            End If
        Next
        For Each e In Array(Array("British Pound", "a2"), Array("US Dollar", "b2"))
            If Sheets("Config & Summary").[i2] Like "*" & e(0) & "*" Then
                myCurr = e(0)
                coef = Sheets("currency").Range(e(1))
                Exit For
            End If
            Next
        If myCurr = "" Then MsgBox "No matched data in ""Config!I2""": Exit Sub
        For Each ws In Worksheets
            With ws.Range("b3", ws.Range("b" & Rows.Count).End(xlUp)).Resize(, 4)
                If Application.CountIf(.Columns(1), "x") Then
                    With .Offset(, 1)
                        .Value = ws.Evaluate("if(b3:b" & .Cells(.Rows.Count, 1).Row & _
                            "=""x""," & .Address & "*" & coef & "," & .Address & ")")
                    End With
                End If
            End With
            ws.[h2] = myCurr
        Next
    End Sub

  2. #2
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: A maco makes all my Vlookups and formulas disappear!!!!

    Hello marvinabou7890,

    Difficult to tell. Do you perhaps have any other Settings or code within your VBA project, which we are unaware of?

    To me, at least, your issue appears as clear as mud, maybe because I am tired, and maybe you would like to attach a sample workbook, to better access your issue.

    Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic


    Hope to be of assistance then, after some shut eye.

    Regards.
    Please consider:

    Be polite. Thank those who have helped you. Then Click on the star icon in the lower left part of the contributor's post and add Reputation. Cleaning up when you're done. If you are satisfied with the help you have received, then Please do Mark your thread [SOLVED] .

  3. #3
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,962

    Re: A maco makes all my Vlookups and formulas disappear!!!!

    Your code is not looking cell by cell for the x - it is just looking for any x. So try changing

        For Each ws In Worksheets
            With ws.Range("b3", ws.Range("b" & Rows.Count).End(xlUp)).Resize(, 4)
                If Application.CountIf(.Columns(1), "x") Then
                    With .Offset(, 1)
                        .Value = ws.Evaluate("if(b3:b" & .Cells(.Rows.Count, 1).Row & _
                            "=""x""," & .Address & "*" & coef & "," & .Address & ")")
                    End With
                End If
            End With
            ws.[h2] = myCurr
        Next
    to this, adding the Dim statements to the top of the Sub

        Dim I As Integer
        Dim C As Range
        
        For Each ws In Worksheets
                For Each C In ws.Range("b3", ws.Range("b" & ws.Rows.Count).End(xlUp))
                    If C.Value = "x" Then
                        For I = 1 to 3
                            C.Offset(0,I).Value = C.Offset(0,I).Value *coef
                        Next I
                    End If
                Next C
            ws.[h2] = myCurr
        Next ws
    Bernie Deitrick
    Excel MVP 2000-2010

  4. #4
    Registered User
    Join Date
    11-06-2015
    Location
    San Diego
    MS-Off Ver
    2013
    Posts
    82

    Re: A maco makes all my Vlookups and formulas disappear!!!!

    HI thank you for the reply,
    I tried it and yes it worked it multiplied the rows without breaking the other formulas however I get a debug error N.2042. I will put the line of code which causes the error below.
    Thank you.
    Your friend
    If C.Value = "x" Then

  5. #5
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,962

    Re: A maco makes all my Vlookups and formulas disappear!!!!

    One of your cells in column B has an #N/A error, so you have other problems than with the code. But this is how you would check for that:

        For Each ws In Worksheets
                For Each C In ws.Range("b3", ws.Range("b" & ws.Rows.Count).End(xlUp))
                    If Not IsError(C.Value) Then
                        If C.Value = "x" Then
                            For I = 1 to 3
                                C.Offset(0,I).Value = C.Offset(0,I).Value *coef
                            Next I
                        End If
                    End If
                Next C
            ws.[h2] = myCurr
        Next ws

  6. #6
    Registered User
    Join Date
    11-06-2015
    Location
    San Diego
    MS-Off Ver
    2013
    Posts
    82

    Re: A maco makes all my Vlookups and formulas disappear!!!!

    hi is there a way you can help me. So I altered the above code a little and it works very well for for just converting from dollars to euros however I need to be able to go back from euros to dollars I have tried a few different methods but am coming up frankly short. For some reason it keeps multipliyng but weird numbers and I am just confused below is the code I have.
    Thank you,
    Your friend
    Sub test123456()
    Dim cr As Worksheet: Set cr = Sheets("currency")
       Dim I As Integer
        Dim C As Range
        Dim ws As Worksheet, e, coef, myCurr As String
        'attempting to convert back from euros first
        'basically here if cell H2 equals euro then it must convert to dollars
        'I will eventually have a similar if statement to convert all currencies back to dollars
        For Each e In Array(Array("Euro", "B1"), Array("US Dollar", "C1"))
            If Sheets("Config & Summary").[H2] Like "*" & e(0) & "*" Then
                myCurr = e(0)
                coef = cr.Range("c2").Value
                Exit For
            End If
            Next
        
        
        
        
        'converting to euros
        For Each e In Array(Array("Euro", "B1"), Array("US Dollar", "C1"))
            If Sheets("Config & Summary").[i2] Like "*" & e(0) & "*" Then
                myCurr = e(0)
                coef = cr.Range("B2").Value
                Exit For
            End If
            Next
            'converting to pounds
        For Each e In Array(Array("British Pound", "B2"), Array("US Dollar", "C2"))
            If Sheets("Config & Summary").[i2] Like "*" & e(0) & "*" Then
                myCurr = e(0)
                coef = cr.Range("B3").Value
                Exit For
            End If
            Next
            
            'checking for n/a error and configuring loop
        If myCurr = "" Then MsgBox "No matched data in ""Config!I2""": Exit Sub
        
       For Each ws In Worksheets
                For Each C In ws.Range("b3", ws.Range("b" & ws.Rows.Count).End(xlUp))
                    If Not IsError(C.Value) Then
                        If C.Value = "x" Then
                            For I = 1 To 4
                                C.Offset(0, I).Value = C.Offset(0, I).Value * coef
                            Next I
                        End If
                    End If
                Next C
            ws.[H2] = myCurr
        Next ws
        
    End Sub

+ 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. Workbook.Save makes Userform Disappear
    By Antenne88 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-26-2015, 06:30 PM
  2. Group - Makes my rows disappear
    By spookiepower in forum Excel General
    Replies: 3
    Last Post: 07-30-2013, 05:06 PM
  3. MouseOver cell that makes apear and disappear an image
    By blakito in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-20-2012, 12:57 PM
  4. MouseOver cell that makes apear and disappear an image
    By first_mo_za in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 06-20-2012, 03:37 AM
  5. Why does #DIV/O appear? Retyping the figures makes it disappear!!
    By HAYLEYFARMINER in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 07-28-2008, 09:20 AM
  6. Insert-Subtotals makes Column Outlines disappear
    By gpie in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 11-22-2005, 12:10 PM
  7. [SOLVED] opening html table in Excel makes preceding 0's disappear??!!
    By yung in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-12-2005, 12:06 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