+ Reply to Thread
Results 1 to 6 of 6

Macro to replace value in a column

  1. #1
    Registered User
    Join Date
    10-26-2022
    Location
    Los Angeles
    MS-Off Ver
    365
    Posts
    12

    Macro to replace value in a column

    Hi guys! New to the forum! Need help please!

    I have a macro that pulls in data from a SharePoint List. I then want to update a value in a column but it's not updating. No errors or anything, values are just not getting updated.

    Sub Refresh_From_SharePoint()
    '
    Sheets("Data").Select
    ' Selection.ListObject.QueryTable.Refresh BackgroundQuery:=False
    Sheets("Data").ListObjects("Table_C_GRV").QueryTable.Refresh BackgroundQuery:=False
    '
    Call Update_Approval
    Sheets("Approvals").Select

    End Sub

    Sub Update_Approval()
    'this will get you the last row number in column "L"
    lastRow = Sheets("Data").Cells(Sheets("Data").Rows.Count, "L").End(xlUp).Row

    'loop through all cells in column "L" and replace text as needed
    For i = 1 To lastRow
    Sheets("Data").Cells(i, 2).Value = Replace(Sheets("Data").Cells(i, 2).Value, "TRUE", "Approved")
    Sheets("Data").Cells(i, 2).Value = Replace(Sheets("Data").Cells(i, 2).Value, "FALSE", "UnApproved")
    Next i
    End Sub

  2. #2
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    1,980

    Re: Macro to replace value in a column

    I think the reason is that .Cells(i,2) is looking at column 2, i.e. B. L would be column 12

    You could probably remove the loop and do replace instead.

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    10-26-2022
    Location
    Los Angeles
    MS-Off Ver
    365
    Posts
    12

    Re: Macro to replace value in a column

    Thank you so much! That worked!

  4. #4
    Registered User
    Join Date
    10-26-2022
    Location
    Los Angeles
    MS-Off Ver
    365
    Posts
    12

    Re: Macro to replace value in a column

    Hi Again,
    They changed it on me again and I can't get it to work properly. Now, instead of replacing a value, they want to replace it or update it based on fields that are populated.

    So based on columns populated, the status should change accordingly:
    1. If columns are populated and status is TRUE - change to APPROVED
    2. If columns are populated and status is FALSE - change to UNAPPROVED
    3. If columns are not populated and status is FALSE - change to PENDING
    Attached Images Attached Images

  5. #5
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    1,980

    Re: Macro to replace value in a column

    Maybe

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    10-26-2022
    Location
    Los Angeles
    MS-Off Ver
    365
    Posts
    12

    Re: Macro to replace value in a column

    Sorry, I should've started a new thread....the last question didn't work for me. The thread for updating a column worked fine. Thanks for your help!

+ 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] Macro to Replace Strings in a Column
    By ner0417 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-15-2017, 03:29 PM
  2. Macro Find and Replace in a new column
    By AnnaLioce in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 03-17-2016, 09:50 AM
  3. Replies: 3
    Last Post: 11-25-2014, 06:08 AM
  4. [SOLVED] Macro to search & replace then copy to another column on the same row?
    By ucsutah in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-08-2012, 09:41 PM
  5. VBA Macro Replace Entire column
    By dwr0211 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 07-25-2011, 04:31 PM
  6. Macro to replace text in column and transfer
    By undergraduate in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-12-2011, 08:39 PM
  7. Macro to replace values in a column
    By vijanand1279 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-06-2011, 10:42 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