+ Reply to Thread
Results 1 to 4 of 4

Macro to Freeze Values of Cells in Present Column, Move Right, Repeat

  1. #1
    Registered User
    Join Date
    05-03-2022
    Location
    Texas
    MS-Off Ver
    2016
    Posts
    21

    Macro to Freeze Values of Cells in Present Column, Move Right, Repeat

    In the attached Test.xlsm, I have columns containing formulas. I would like to set up a macro that will freeze those formulas (i.e., convert to fixed values): freeze the next 10 columns, save, move to the 11th column, repeat. So far, my macro looks like this:

    Please Login or Register  to view this content.
    Questions and problems:

    1. I don't know how to specify the next 10 columns relative to the present point. This code refers to columns A through J because I started in cell A1. But how can I get it to refer to the next 10 columns after I've moved to cell K1?
    2. After freezing the next 10 columns, I need to move to the 11th column, same row. At present, I have Range("K1").Select. Should I use something like ActiveSheet.Cells(11,0).Select ?
    3. Ideally, to stop when it reaches a column with no data on row 1, I think I should use Do While - Cells(i,1).Value = but I'm not sure how to represent a null value.
    Attached Files Attached Files

  2. #2
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,468

    Re: Macro to Freeze Values of Cells in Present Column, Move Right, Repeat

    I'm not sure why the need to do this in chunks of 10 columns rather than just the whole lot in one go, but give the below a try and see it if works as required.
    Please Login or Register  to view this content.
    BSB

  3. #3
    Registered User
    Join Date
    05-03-2022
    Location
    Texas
    MS-Off Ver
    2016
    Posts
    21

    Re: Macro to Freeze Values of Cells in Present Column, Move Right, Repeat

    Thanks, BSB. Much more elegant than what I had. I have to admit it mystifies me. But it works.

    I guess you figured out that my uploaded sample spreadsheet inadvertently has the formulas already converted to values in the first 10 columns.

    The key missing piece is the save after each 10 columns. I wanted to pause after each save, to view cell contents and verify it's working as intended, so I tried this variation on your code:
    Please Login or Register  to view this content.
    but (a) it's annoying to have to add so much clutter and (b) the resulting input box doesn't allow me to inspect cell contents, to see whether ActiveWorkbook.Save is working as intended.

    I saw somewhere that a backslash can be used to insert a simple pause (or I guess the correct term is Stop) in macro execution, but I couldn't quite find out how to make that work.

  4. #4
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,468

    Re: Macro to Freeze Values of Cells in Present Column, Move Right, Repeat

    If all you want to to is stop the code running temporarily, put your cursor on the line of code you wish to pause at and press the F9 key to insert a break point.
    The code will run until that line and you can go examine the results, then when you wish to start it again just press F5 whilst in the VB editor.

    BSB

+ 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. Replies: 1
    Last Post: 03-29-2018, 10:20 PM
  2. [SOLVED] If cells match then freeze (copy paste values) in each column in the workbook.
    By BPSJACK in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 09-16-2015, 06:12 AM
  3. Replies: 2
    Last Post: 09-03-2014, 03:37 AM
  4. How to bring comma separated values present in a column into cells in next row?
    By Palraj in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-28-2014, 08:17 AM
  5. Making a macro repeat for all values in column and leave results on WS2
    By jackuspi2010 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-19-2013, 12:34 PM
  6. Replies: 0
    Last Post: 03-13-2013, 11:59 AM
  7. Macro - Copy/Paste certain cells and move down column and repeat
    By rohan87 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-16-2013, 02:02 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