+ Reply to Thread
Results 1 to 10 of 10

If a condition is met convert range to value from formula

Hybrid View

Mothergreen If a condition is met convert... 01-10-2016, 07:50 PM
humdingaling Re: If a condition is met... 01-10-2016, 07:53 PM
Mothergreen Re: If a condition is met... 01-10-2016, 08:22 PM
gmr4evr1 Re: If a condition is met... 01-10-2016, 08:31 PM
Mothergreen Re: If a condition is met... 01-11-2016, 10:19 AM
humdingaling Re: If a condition is met... 01-10-2016, 08:35 PM
Mothergreen Re: If a condition is met... 01-11-2016, 12:14 PM
JOHN H. DAVIS Re: If a condition is met... 01-11-2016, 04:00 PM
humdingaling Re: If a condition is met... 01-11-2016, 07:01 PM
Mothergreen Re: If a condition is met... 01-13-2016, 11:49 AM
  1. #1
    Registered User
    Join Date
    08-08-2012
    Location
    Winter Park, Florida
    MS-Off Ver
    Excel2010
    Posts
    12

    If a condition is met convert range to value from formula

    Good Afternoon All

    First I just want to thank everyone on here regardless of solution. I have been following this board for a while and this site has always helped me expand my knowledge of VBA. I am no expert by any means but i now enough to get myself into trouble.

    Image if you will of a spreadsheet where in column A you have a drop down with two options to pick from open and close.

    Columns B - E have formulas in them that pull from another sheet (specifically vlookup formulas)

    What i am trying to accomplish is this. If a person selects close from the drop down in column A, columns (B-E), on that row, gets converted from the vlookup formula to its value.

    I have tried writing this a number of way but either excel says that there is a problem with the code or i get the wrong result. I just can't seem to get it to specify to the specific rows that meet the condition. This is the closest working code that i have so far:

    Sub Celladjust()
    
     Dim rng As Range
        
       Set rng = Range("A:A")
       For Each Cell In rng
           If Cell.Value = "close" Then
        Columns("B:E").Select
        Selection.Copy
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        End If
        Next
    End Sub
    I have tried specifying range for rows but I am doing something wrong.

    If someone can help point me in the right direction with this that would be amazing.
    Thank you all.
    MG
    Last edited by Mothergreen; 01-10-2016 at 08:19 PM.

  2. #2
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: If a condition is met convert range to value from formula

    Post withdrawn
    Last edited by humdingaling; 01-10-2016 at 08:22 PM.
    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

  3. #3
    Registered User
    Join Date
    08-08-2012
    Location
    Winter Park, Florida
    MS-Off Ver
    Excel2010
    Posts
    12

    Re: If a condition is met convert range to value from formula

    Adjusted sorry about that. First time posting code on the forum

  4. #4
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: If a condition is met convert range to value from formula

    The only thing I did was add
    Dim cell as Range
    to your code and it seemed to work
    1N73LL1G3NC3 15 7H3 4B1L17Y 70 4D4P7 70 CH4NG3 - 573PH3N H4WK1NG
    You don't have to add Rep if I have helped you out (but it would be nice), but please mark the thread as SOLVED if your issue is resolved.

    Tom

  5. #5
    Registered User
    Join Date
    08-08-2012
    Location
    Winter Park, Florida
    MS-Off Ver
    Excel2010
    Posts
    12

    Re: If a condition is met convert range to value from formula

    I did that as well. Specifying the range and for it to specifically affect only the rows that meet the requirements still eludes me. Its either all or nothing when i specify a range either a excel says something is wrong with the range or at the first close it goes through the whole spreadsheet and changes all the formulas in rows B-E

  6. #6
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: If a condition is met convert range to value from formula

    not a problem

    possible solution you can use below

    Sub CellAdjust()
        
        Dim i As Long
        
        For i = 1 To ActiveSheet.UsedRange.Rows.Count
        
            If Cells(i, 1) = "Close" Then
                Range(Cells(i, 2), Cells(i, 5)).Value = Range(Cells(i, 2), Cells(i, 5)).Value
            End If
    
        Next
    End Sub
    Mock up file attached
    Attached Files Attached Files
    Last edited by humdingaling; 01-10-2016 at 08:48 PM. Reason: typo

  7. #7
    Registered User
    Join Date
    08-08-2012
    Location
    Winter Park, Florida
    MS-Off Ver
    Excel2010
    Posts
    12

    Re: If a condition is met convert range to value from formula

    Thank You Humdingaling this worked. This looks much simpler then what i was doing. I guess i have spent to much time learning from recording macros instead of branching out. I am going to try this code on a similar sheet that goes on for about 3000+ rows fingers crossed .

  8. #8
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: If a condition is met convert range to value from formula

    FWIW:

    Sub Mothergreen()
     Dim rng As Range
     With Application
        .DisplayAlerts = False
        .ScreenUpdating = False
        .Calculation = xlManual
    End With
       Set rng = Range("A:A")
       For Each cell In rng
           If cell.Value = "close" Then
                With Range(Cells(cell.row, "B"), Cells(cell.row, "E"))
                    .Value = .Value
                End With
        End If
        Next
    With Application
        .DisplayAlerts = True
        .Calculation = xlCalculationAutomatic
        .ScreenUpdating = True
    End With
    End Sub

  9. #9
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: If a condition is met convert range to value from formula

    just to explain my code further

    the "i" in my code represents the "current" row

    For i = 1 To ActiveSheet.UsedRange.Rows.Count
    so it starts from row one (i = 1) and loops until "ActiveSheet.UsedRange.Rows.Count" which should represent your last row
    this helps a bit in the code running faster so it doesnt loop for million+ rows

    syntax for cells (rows,columns)

    so this line
    If Cells(i, 1) = "Close" Then
    looks at column 1 which is A

    i = 1 then a1, i = 2 then a2, i = 3 then a3....etc

    rest of the code is self explanatory

    Range(Cells(i, 2), Cells(i, 5)).Value = Range(Cells(i, 2), Cells(i, 5)).Value
    this just copies the value and replaces with value ...its another way of doing pastespecial - values

  10. #10
    Registered User
    Join Date
    08-08-2012
    Location
    Winter Park, Florida
    MS-Off Ver
    Excel2010
    Posts
    12

    Thumbs up Re: If a condition is met convert range to value from formula

    Thank you all for your time and help. This is exactly what i needed and thank you for the amazingly quick reply. You all make this board awesome.

+ 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. VBA-Excel to convert Tax Formula with condition
    By Parth007 in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 03-12-2015, 04:54 PM
  2. Replies: 2
    Last Post: 09-01-2014, 07:59 AM
  3. Need formula using 'If' condition & inserting a specific range.
    By andyzz in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 07-26-2014, 02:58 AM
  4. [SOLVED] Looping through a range and inserting a formula where condition met
    By strud in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-06-2014, 06:24 AM
  5. Formatting a range and Adding a formula to convert the range.
    By Technodruid in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-28-2010, 02:22 PM
  6. How to you convert condition to formula?
    By stormracela in forum Excel General
    Replies: 1
    Last Post: 05-27-2010, 05:18 AM
  7. Index Formula - adding a range condition
    By Henry c in forum Excel General
    Replies: 2
    Last Post: 04-29-2010, 10:19 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