VBA - Variable Value Won't Update

Ben M

New Member
Joined
Aug 13, 2014
Messages
21
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:

Some videos you may like

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
46,340
Office Version
  1. 365
Platform
  1. Windows
Try it like
Code:
Dim CheckValue As String
Do While CheckValue <> ""

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

rlv01

Well-known Member
Joined
May 16, 2017
Messages
771
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
 

Ben M

New Member
Joined
Aug 13, 2014
Messages
21
Both suggestions were required. It works fully now.

Thank you very much guys :biggrin:
 

Watch MrExcel Video

Forum statistics

Threads
1,109,021
Messages
5,526,299
Members
409,694
Latest member
bastos21

This Week's Hot Topics

Top