VBA - Variable Value Won't Update

Ben M

New Member
Joined
Aug 13, 2014
Messages
23
Hi,

This is the first loop I've written. It seems to do exactly what I intended except it doesn't end. When I hover over the CheckValue it stay's as "Column 1" even though it should increase to Column 2,3,4 etc with each iteration. Eventually It will be eventually be blank as all the headings will be deleted point I want the loop to end.

Code:
Sub Part4_Loop()

Dim CheckValue As String

CheckValue = Worksheets("Temp Sheet").Range("D1").Value

Do While CheckValue <> " "

Sheets("Temp Sheet").Activate
    Range("A2").Select
    Range(Selection, Selection.End(xlDown)).Select
    Range(Selection.Offset(0, 3), ActiveCell.Offset(0, 0)).Copy

Sheets("Imaging Report Summary").Activate
    Worksheets("Imaging Report Summary").Range("A1").End(xlDown).Offset(1, 0).Select
    ActiveSheet.Paste

Sheets("Temp Sheet").Activate
Columns("D").EntireColumn.Delete

Loop

End Sub
 
Last edited:

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Try it like
Code:
Dim CheckValue As String
Do While CheckValue <> ""

CheckValue = Worksheets("Temp Sheet").Range("D1").Value
 
Upvote 0
You need to update CheckValue each time the loop executes. For example:

Code:
Sub Part4a_Loop()
    Dim CheckValue As String
    CheckValue = Worksheets("Temp Sheet").Range("D1").Value

    Do While CheckValue <> " "
        Sheets("Temp Sheet").Activate
        Range("A2").Select
        Range(Selection, Selection.End(xlDown)).Select
        Range(Selection.Offset(0, 3), ActiveCell.Offset(0, 0)).Copy

        Sheets("Imaging Report Summary").Activate
        Worksheets("Imaging Report Summary").Range("A1").End(xlDown).Offset(1, 0).Select
        ActiveSheet.Paste

        Sheets("Temp Sheet").Activate
        Columns("D").EntireColumn.Delete

        CheckValue = Worksheets("Temp Sheet").Range("D1").Value

    Loop
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top