How do you pause a Macro to move the cursor from the cell it is on to another cell

Trebor J

New Member
Joined
Jun 17, 2021
Messages
12
Office Version
  1. 2016
Platform
  1. Windows
How do you pause a Macro and be allowed to move the cursor from the cell it is on to another cell?

I have written a macro that copies in a template consisting of 2 formulas and 2 input cells, all on the same row.

After the template is copied in, the cursor moves to the first input cell.

After data is entered and “Enter” pressed, the cursor moves to the second input cell.

After data is entered and “Enter” pressed, the cursor moves down one row and left 3 columns to sit in the cell just below the start of where the template was entered.

A message box then asks if you wish to “Move to Approximate Next Period End”.

If you click on Yes, the cursor then moves down 29 Rows.

All well and good except you might not be in the cell that is in the row that has a cell with the date you want in it. You need to move the cursor up or down a row or two.

I found some coding on the internet that purports to pause the Macro and allows one to move the cursor and it appears to do that.
I say “appears to do that” because a Message Box appears giving one the option to move the cursor, from the FROM CELL to the TO CELL, with the FROM CELL having a “Solid” border around it and the TO Cell having a “Dashed” border around it, if a new cell is chosen. The Message Box will then show the absolute address of the TO CELL.

If you then click on OK a new Message Box appears telling you that the Macro is “Working with the TO CELL’s address”. The TO Cell no longer has a “dashed” border. The FROM Cell still has a “Solid” border.

If you then click on OK to go ahead and then Yes to copy in the template, the template is copied into the FROM CELL. Not what I want !@%&). It should be copied into the TO CELL.

Any help or suggestion would be very much appreciated. Thanks guys and girls.

VBA Code:
Sub CopyInPeriodTotalsFormulasTesting()

Dim MykWh1 As Variant
Dim MykWh2 As Variant

Dim vbResult As VbMsgBoxResult

  Do Until IsEmpty(ActiveCell.Offset(0, -1))

  vbResult = MsgBox("    ***    COPY IN PERIOD TOTALS FORMULAS    ***     " & Chr(10) & Chr(10) & "  CHECK TO SEE CURSOR IS IN THE CORRECT CELL      ", vbYesNo, "CONTINUE Y/N?")

    If vbResult = vbYes _
      Then
        ActiveCell.Offset(0, 0).Select
          Range("PeriodTotalsFormulas").Copy Destination:=ActiveCell.Offset(0, 0)      '   Copy in the PeriodTotalFormula into the current cell
           
            ActiveCell.Offset(0, 2).Select
              MykWh1 = InputBox("Enter the kWh for 49")
               ActiveCell.Value = MykWh1
               
            ActiveCell.Offset(0, 1).Select
              MykWh2 = InputBox("Enter the kWh for 64")
                ActiveCell.Value = MykWh2
               
        ActiveCell.Offset(1, -3).Select
       
        vbResult = MsgBox("  Move to Approx Next Period End   ", vbYesNo, "CONTINUE Y/N?")
       
        If vbResult = vbYes _
          Then
            ActiveCell.Offset(29, 0).Select                  'Move to next approximate cell below

            Dim Rng As Range
              On Error Resume Next
                Set Rng = Application.InputBox("Enter to Continue " & _
                        "or Select a cell with the Mouse", _
                        "Cell entry", ActiveCell.Address, , , , , 8)
                If Rng Is Nothing Then
                    MsgBox "You cancelled!"
                Else
                  MsgBox "Working with cell " & Rng(1).Address

                End If
         
          Else
            Exit Do
        End If
           
      Else
        Exit Do
     
    End If

Loop
 
End Sub

MovingTheCursorTesting 20221109 1852.xlsm
ABCDEFGHIJKLMNOP
1
2Data for Moving the Cursor Testing
3
4DATEDaily kW hrsPeriod Total kW hrsInvoiced kWh
5Totalu49u64
6
7
816-Nov-1528.9028.90- Period Total Formula
917-Nov-1517.70
1018-Nov-1522.84
1119-Nov-1526.29
1220-Nov-1523.43
1321-Nov-1522.63
1422-Nov-1514.17
1523-Nov-1521.65
1624-Nov-1512.54
1725-Nov-1511.35
1826-Nov-1534.90
1927-Nov-1546.42
2028-Nov-1551.17
2129-Nov-1550.52
2230-Nov-1538.09
2301-Dec-1529.71
2402-Dec-1535.24
2503-Dec-1544.87
2604-Dec-1543.85
2705-Dec-1540.08
2806-Dec-1539.68
2907-Dec-1548.57
3008-Dec-1539.57
3109-Dec-1538.32
3210-Dec-1534.87
3311-Dec-1528.82
3412-Dec-1529.97
3513-Dec-1532.39
3614-Dec-1541.39
3715-Dec-1542.27
3816-Dec-1532.11StartStart the macro from cell D38
3917-Dec-1539.25Note the Months vary from 31, 30 & 28 days
4018-Dec-1548.59 and the invoice is not always the same day of the month
4119-Dec-1544.95 hence need for ability to move the cursor.
4220-Dec-1541.10
4321-Dec-1532.45
4422-Dec-1536.08
4523-Dec-1542.15The Testing Macro will copy in the Template from cells D8:G8, and then take one to the Input Cells. Just enter any number into each of those 2 cells, and then follow the Messages to go through the proceedure. When requested move the cursor to the next 16th of the month cell.
4624-Dec-1540.62
4725-Dec-1533.86
4826-Dec-1526.67
4927-Dec-1529.36
5028-Dec-1531.38
5129-Dec-1528.15
5230-Dec-1529.76
5331-Dec-1534.27
5401-Jan-1624.19
5502-Jan-1627.83
5603-Jan-1625.08
5704-Jan-1649.32
5805-Jan-1641.48
5906-Jan-1634.25
6007-Jan-1628.42
6108-Jan-1628.43
6209-Jan-1634.72
6310-Jan-1621.53
6411-Jan-1633.26
6512-Jan-1630.88
6613-Jan-1632.73
6714-Jan-1634.51
6815-Jan-1632.07
6916-Jan-1630.02NextD69 is the Next cell to copy the template into.
7017-Jan-1633.26
7118-Jan-1624.31
7219-Jan-1620.14
7320-Jan-1619.52
7421-Jan-1619.13
7522-Jan-1622.89
7623-Jan-1627.83
7724-Jan-1629.13
7825-Jan-1625.72
7926-Jan-1632.10
8027-Jan-1628.36
8128-Jan-1623.22
8229-Jan-1632.54
8330-Jan-1626.29
8431-Jan-1627.35
8501-Feb-1624.21
8602-Feb-1629.18
8703-Feb-1627.22
8804-Feb-1630.62
8905-Feb-1632.56
9006-Feb-1629.34
9107-Feb-1625.93
9208-Feb-1630.58
9309-Feb-1629.40
9410-Feb-1625.25
9511-Feb-1630.79
9612-Feb-1627.29
9713-Feb-1626.08
9814-Feb-1627.79
9915-Feb-1628.23
10016-Feb-1625.79Next
10117-Feb-1628.12
10218-Feb-1627.50
10319-Feb-1622.92
10420-Feb-1628.76
10521-Feb-1627.85
10622-Feb-1625.28
10723-Feb-1628.63
10824-Feb-1626.60
10925-Feb-1633.88
11026-Feb-1627.21
11127-Feb-1625.48
11228-Feb-1627.48
11329-Feb-1629.00
11401-Mar-1624.01
11502-Mar-1629.31
11603-Mar-1627.85
11704-Mar-1623.21
11805-Mar-1622.86
11906-Mar-1627.91
12007-Mar-1627.11
12108-Mar-1630.77
12209-Mar-1628.07
12310-Mar-1624.27
12411-Mar-1625.00
12512-Mar-1630.45
12613-Mar-1626.99
12714-Mar-1632.15
12815-Mar-1628.89
12916-Mar-1627.65Next
13017-Mar-1629.04
13118-Mar-1628.74
13219-Mar-1633.60
13320-Mar-1629.67
13421-Mar-1626.62
13522-Mar-1632.27
13623-Mar-1627.61
13724-Mar-1626.75
13825-Mar-1626.52
13926-Mar-1631.65
14027-Mar-1623.74
14128-Mar-1629.15
14229-Mar-1628.04
14330-Mar-1628.29
14431-Mar-1625.82
14501-Apr-1627.32
14602-Apr-1628.14
14703-Apr-1630.21
14804-Apr-1628.20
14905-Apr-1633.65
15006-Apr-1631.01
15107-Apr-1626.81
15208-Apr-1627.10
15309-Apr-1631.83
15410-Apr-1625.37
15511-Apr-1627.50
15612-Apr-1633.30
15713-Apr-1634.12
15814-Apr-1627.30
15915-Apr-1623.56
16016-Apr-1623.56Next
161TEST END
162
163
Testing
Cell Formulas
RangeFormula
D8D8=SUM($C$7:C8)-SUM($D$7:D7)
E8E8=+F8+G8
 
Using my example data, above:
I started my macro, which copied in the template and requested me to enter data in cells F8 & G8.
I have done that and am in cell G8.
I now want to move down to the cell in column D that is in the row that has the date of 16/12/2015 in it.
I do not know that cells address and do not know how many rows down it is, so I am thinking that if the macro asked me to enter the date of 16/12/2015, or even just 16, it would go down to that cell in column B with that date in it, and then to column D in that row.
I would then be in the cell I want to be in, and the macro would loop back to the start.
I look forward to your scrip.
Thanks
There is a type script where if you double click on a cell something can happen
And then if you double click on another cell something else can happen. If this might work let me know with specifics

Like if I double click on A1 do this
If I double, click on B45 do this
 
Upvote 0

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
There is a type script where if you double click on a cell something can happen
And then if you double click on another cell something else can happen. If this might work let me know with specifics

Like if I double click on A1 do this
If I double, click on B45 do this
From your reply to what I have described, I am concluding that you are unable to produce scrip that will do what I want.
Is that correct or have I miss-understood you ?
 
Upvote 0
From your reply to what I have described, I am concluding that you are unable to produce scrip that will do what I want.
Is that correct or have I miss-understood you ?
This is beyond my knowledgebase.
I will continue to monitor this thread to see what I can learn.
 
Upvote 0
Hello Readers.

After much thought and trial and error I have, myself, solved the problem I was seeking help on.

I have moved away from the concept of having the macro pause, and allow one to move the cursor to a different cell. I received a suggestion from a member of another forum, but while there where good indications that it was working, that proved not to be the case.

I then gave thought to the “Railway Line” concept and using an existing column of consecutive dates, together with entering a desired date, have managed to land in the cell I want to be in. From there the macro inserts a template which produces a Period End Total of Consumption, allows one to enter Invoiced Consumption, and shows the difference between the two. It then repeats for the next period, and gives a warning when near the end of the data.

A sample of the worksheet is below, followed by the code.

Any suggested refinements are welcomed.

Cheers, T J

Inserting a Period Total Formula and Entering Comparative Data 20221118 1936.xlsm
ABCDEFGHIJKLMNOPQ
1
2Data for Demonstrating the Macro for Inserting a Period Total Formual and Entering Comparative DataThe OBJECTIVE of this Macro to: add up the consumption for each billing period and compare it with the consumption that has been invoiced.
3
4DATEDaily kW hrsPeriod Total kW hrsInvoiced kWh
5Totalu49u64
6 <-- Be in column D and Click on the START button to commence
7
816-Nov-1528.9028.90560.0053030 Period Total Formula
917-Nov-1517.70
1018-Nov-1522.84START the macro from the first Cell in COLUMN D that you wish to insert a Period Total Formula
1119-Nov-1526.29
1220-Nov-1523.43
1321-Nov-1522.63
1422-Nov-1514.17The Macro will copy in the Template from cells D8:G9, and then take you to the Input Cells. Just enter any number into each of those 2 cells, and then follow the Messages to go through the proceedure.
1523-Nov-1521.65
1624-Nov-1512.54
1725-Nov-1511.35
1826-Nov-1534.90
1927-Nov-1546.42
2028-Nov-1551.17When you approach the bottom of the data you will be given a warning. You may not be able to see the date for the last row of the data, so you should make a note of it before commencing.
2129-Nov-1550.52
2230-Nov-1538.09
2301-Dec-1529.71
2402-Dec-1535.24
2503-Dec-1544.87
2604-Dec-1543.85Range Names & Locations
2705-Dec-1540.08
2806-Dec-1539.68
2907-Dec-1548.57FinalPeriodTotalsFormulas=Testing!$D$8:$G$8
3008-Dec-1539.57
3109-Dec-1538.32PeriodTotalsFormulas=Testing!$D$8:$G$9
3210-Dec-1534.87
3311-Dec-1528.82
3412-Dec-1529.97
3513-Dec-1532.39
3614-Dec-1541.39
3715-Dec-1542.27
3816-Dec-1532.11
3917-Dec-1539.25
4018-Dec-1548.59
4119-Dec-1544.95
4220-Dec-1541.10
4321-Dec-1532.45
4422-Dec-1536.08
4523-Dec-1542.15
4624-Dec-1540.62
4725-Dec-1533.86
4826-Dec-1526.67
4927-Dec-1529.36
5028-Dec-1531.38
5129-Dec-1528.15
5230-Dec-1529.76
5331-Dec-1534.27
5401-Jan-1624.19
5502-Jan-1627.83
5603-Jan-1625.08
5704-Jan-1649.32
5805-Jan-1641.48
5906-Jan-1634.25
6007-Jan-1628.42
6108-Jan-1628.43
6209-Jan-1634.72
6310-Jan-1621.53
6411-Jan-1633.26
6512-Jan-1630.88
6613-Jan-1632.73
6714-Jan-1634.51
6815-Jan-1632.07
6916-Jan-1630.02
7017-Jan-1633.26
7118-Jan-1624.31
7219-Jan-1620.14
7320-Jan-1619.52
7421-Jan-1619.13
7522-Jan-1622.89
7623-Jan-1627.83
7724-Jan-1629.13
7825-Jan-1625.72
7926-Jan-1632.10
8027-Jan-1628.36
8128-Jan-1623.22
8229-Jan-1632.54
8330-Jan-1626.29
8431-Jan-1627.35
8501-Feb-1624.21
8602-Feb-1629.18
8703-Feb-1627.22
8804-Feb-1630.62
8905-Feb-1632.56
9006-Feb-1629.34
9107-Feb-1625.93
9208-Feb-1630.58
9309-Feb-1629.40
9410-Feb-1625.25
9511-Feb-1630.79
9612-Feb-1627.29
9713-Feb-1626.08
9814-Feb-1627.79
9915-Feb-1628.23
10016-Feb-1625.79
10117-Feb-1628.12
10218-Feb-1627.50
10319-Feb-1622.92
10420-Feb-1628.76
10521-Feb-1627.85
10622-Feb-1625.28
10723-Feb-1628.63
10824-Feb-1626.60
10925-Feb-1633.88
11026-Feb-1627.21
11127-Feb-1625.48
11228-Feb-1627.48
11329-Feb-1629.00
11401-Mar-1624.01
11502-Mar-1629.31
11603-Mar-1627.85
11704-Mar-1623.21
11805-Mar-1622.86
11906-Mar-1627.91
12007-Mar-1627.11
12108-Mar-1630.77
12209-Mar-1628.07
12310-Mar-1624.27
12411-Mar-1625.00
12512-Mar-1630.45
12613-Mar-1626.99
12714-Mar-1632.15
12815-Mar-1628.89
12916-Mar-1627.65
13017-Mar-1629.04
13118-Mar-1628.74
13219-Mar-1633.60
13320-Mar-1629.67
13421-Mar-1626.62
13522-Mar-1632.27
13623-Mar-1627.61
13724-Mar-1626.75
13825-Mar-1626.52
13926-Mar-1631.65
14027-Mar-1623.74
14128-Mar-1629.15
14229-Mar-1628.04
14330-Mar-1628.29
14431-Mar-1625.82
14501-Apr-1627.32
14602-Apr-1628.14
14703-Apr-1630.21
14804-Apr-1628.20
14905-Apr-1633.65
15006-Apr-1631.01
15107-Apr-1626.81
15208-Apr-1627.10
15309-Apr-1631.83
15410-Apr-1625.37
15511-Apr-1627.50
15612-Apr-1633.30
15713-Apr-1634.12
15814-Apr-1627.30
15915-Apr-1623.56
16016-Apr-1623.56
161DATA END
162
163
164kW hrs4,595.4228.90560.00530.0030.00
165
166Zero Proofs4,566.52-
167
168
169
Demo
Cell Formulas
RangeFormula
D8D8=SUM($C$7:C8)-SUM($D$7:D7)
E8E8=+F8+G8
C164:G164C164=SUM(C8:C163)
C166C166=+C164-D164
E166E166=+E164-F164-G164
Named Ranges
NameRefers ToCells
FinalPeriodTotalsFormulas=Demo!$D$8:$G$8D164
PeriodTotalsFormulas=Demo!$D$8:$G$9D164


VBA Code:

Sub CopyInPeriodTotalsFormulas()

Dim MykWh1 As Variant
Dim MykWh2 As Variant

Dim vbResult As VbMsgBoxResult

ActiveCell.Offset(0, 0).Select
Range("PeriodTotalsFormulas").Copy Destination:=ActiveCell.Offset(0, 0) ' Copy in the PeriodTotalFormula into the current cell

ActiveCell.Offset(0, 2).Select
MykWh1 = InputBox("Enter the kWh for 49")
ActiveCell.Value = MykWh1

ActiveCell.Offset(0, 1).Select
MykWh2 = InputBox("Enter the kWh for 64")
ActiveCell.Value = MykWh2

ActiveCell.Offset(1, -3).Select

Call CompareDates

End Sub


Sub CompareDates()

Dim MyDate As Date
Dim vbResult As VbMsgBoxResult
Dim Ans As Long

ActiveCell.Select
ActiveCell = MyDate
MyDate = InputBox("Enter the Date for the Start of the Next Period")
ActiveCell.Value = MyDate

If IsEmpty(ActiveCell.Offset(30, -1)) _
Then
Ans = MsgBox(" *** You are Near THE END *** " & Chr(10) & Chr(10) _
& " *** You MUST END the Macro NOW *** ", vbYesNo, "CONTINUE Y/N?")
If Ans = vbYes Then
Call CopyInFinalPeriodTotals
End If
Exit Sub

Else
Do Until ActiveCell.Offset(0, -2) = MyDate _

ActiveCell.Offset(1, 0).Select

Loop

End If

ActiveCell = ("Next") 'Labels the next cell for entry & to faciliate railwayline proceedure
Selection.End(xlUp).Select
ActiveCell.ClearContents 'Clear the contents from the MyDate cell
Selection.End(xlDown).Select

Call CopyInPeriodTotalsFormulas

End Sub

Sub CopyInFinalPeriodTotals()

ActiveCell.Offset(0, -1).Select
Selection.End(xlDown).Select
ActiveCell.Offset(0, 1).Select

Range("FinalPeriodTotalsFormulas").Copy Destination:=ActiveCell.Offset(0, 0)

ActiveCell.Offset(0, 2).Select
MykWh1 = InputBox("Enter the kWh for 49")
ActiveCell.Value = MykWh1

ActiveCell.Offset(0, 1).Select
MykWh2 = InputBox("Enter the kWh for 64")
ActiveCell.Value = MykWh2

ActiveCell.Offset(0, -3).Select

Selection.End(xlUp).Select
ActiveCell.ClearContents 'Clear the contents from the MyDate cell
Selection.End(xlDown).Select
ActiveCell.Offset(1, 0).Select

Exit Sub

End Sub

'*************************************************************************************************************

'Sub PauseMacroToMoveCursorToAnotherCell()

'' Appears to work, but not quite.

' vbResult = MsgBox(" Move to Approx Next Period End ", vbYesNo, "CONTINUE Y/N?")
'
' If vbResult = vbYes _
' Then
' ActiveCell.Offset(29, 0).Select 'Move to next approximate cell below
'
' Dim Rng As Range
' On Error Resume Next
' Set Rng = Application.InputBox("Enter to Continue " & _
' "or Select a cell with the Mouse", _
' "Cell entry", ActiveCell.Address, , , , , 8)
' If Rng Is Nothing Then
' MsgBox "You cancelled!"
' Else
' MsgBox "Working with cell " & Rng(1).Address
'
' End If
'
' Else
' Exit Do
' End If
'End Sub
Code:
 
Upvote 0

Forum statistics

Threads
1,215,061
Messages
6,122,921
Members
449,094
Latest member
teemeren

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