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
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Add this at the point where you want to wait:
Application.Wait (Now + TimeValue("0:00:10"))
Although it would be better if you could modify the macro to minimize the required user interaction.

range.select is not necessary, you can use
set cell = activesheet.range("A1") or set cell=activesheet.columns(1).find(.... or set cell=inputbox(....8....
cell.value= ....
 
Upvote 0
Add this at the point where you want to wait:
Application.Wait (Now + TimeValue("0:00:10"))
Although it would be better if you could modify the macro to minimize the required user interaction.

range.select is not necessary, you can use
set cell = activesheet.range("A1") or set cell=activesheet.columns(1).find(.... or set cell=inputbox(....8....
cell.value= ....
Hi Alex,
Thanks for your reply.

I previously tried using "Application.Wait (Now + TimeValue("0:00:10"))", but it does not allow one to move the cursor to another cell.
It just gives you 10 seconds before a message box comes up.

Some of the user interaction is a bit much, and I would cut a lot out so that one wizzes through only entering the input data, if I could find a solution to my question.

I not sure about how to use your suggestion:
set cell = activesheet.range("A1") or set cell=activesheet.columns(1).find(.... or set cell=inputbox(....8....cell.value= ....

The ("A1") part looks as though it is locking on to cell Address A1, which I don't think is going to help.
Can you clarify for me please.
 
Upvote 0
To those who are reading this, I should mention that the Range "PeriodTotalsFormulas" refers to the cells D8:G8.
This is the first time I have used XL2BB. I missed out on ensuring that Range Names were shown alongside the Cell Formulas in the Mini Worksheet pasted in.
 
Upvote 0
I have been watching this posting but have not commented.
I think it would be best to tell us your overall objective here.
Wanting a script to pause so you can move the cursor and then run some more code and then pause again for the cursor to be moved again is not a good way to do things. And using wait just stops the script from running for a few seconds but you cannot move the cursor during this time.

So again, it would be best to tell us your overall objective without thinking you need to move the cursor. And using select on and on is not the way to write a script.
Like if you want to enter the value "Alpha" into sheet named "Bravo" Range("G1")

All you need to do is write the code like this:

Sheets("Bravo").Range("G1").value="Alpha"

See I selected nothing

But some users think first you have to select or activate the sheet name "Bravo"
Then select Range("G1") and then write code saying selection.value="Alpha"
 
Upvote 0
I have been watching this posting but have not commented.
I think it would be best to tell us your overall objective here.
Wanting a script to pause so you can move the cursor and then run some more code and then pause again for the cursor to be moved again is not a good way to do things. And using wait just stops the script from running for a few seconds but you cannot move the cursor during this time.

So again, it would be best to tell us your overall objective without thinking you need to move the cursor. And using select on and on is not the way to write a script.
Like if you want to enter the value "Alpha" into sheet named "Bravo" Range("G1")

All you need to do is write the code like this:

Sheets("Bravo").Range("G1").value="Alpha"

See I selected nothing

But some users think first you have to select or activate the sheet name "Bravo"
Then select Range("G1") and then write code saying selection.value="Alpha"
Hi

Thankyou for replying to my post.

Back in 2015 my electricity supplier came and replaced the Manually Read Meters with Smart Meters that could be read remotely. Down the track, it provided a facility on its web site whereby, after registering, a consumer would have access to all of their account information and be able to download consumption details.

The consumption details entail the kW hours consumed every half hour during the day.

I had a look at what I had consumed over several billing periods and compared it with the totals showing on the invoices charging me for that consumption. They did not reconcile, and the differences were not in my favour.

As a consequence of that I downloaded all available data and am in the process of building macros to analyse it.

I had 122,324 rows of information, in date and time order.

There are 48 ½hrs in a day. 122,324 -:- 48 = 2548.41667, which signifies that something is wrong because I should have got a whole number.

The data downloaded included columns for Date, Start Time, End Time and kWh.

I then set up some columns, formulas and macros to run through the data to ensure that there were 48 rows for each day, and to highlight if not. That produced a number of cases where there had been double ups, 50 rows for a day, and missings, 46 rows for a day. I adjusted for them and now have 122,304 rows of data covering 2548 days.

I then set up a macro to take that data and transpose it onto another worksheet so that the ½hr consumption for a day was set across 48 columns, with a column showing the total consumption for a day. I now have 2548 rows of data, comprising approximately 85 billing periods.

OBJECTIVE

The objective now is to add up the consumption for each billing period and compare it with the consumption invoiced to me, and do it by way of an efficient macro.

It could well be that there is some code that could be written to allow the next date to be entered and the macro will look down the Date Column to find that row, then position itself in the correct cell in that row, to copy in the “PeriodTotalsFormulas”, then move to the first input cell.

I want to use these macros to do this analysis for my offspring and interested friends, so even though I have analysed my data, there is still more to do.

The macro I have built does the job but has the draw back that it does not always stop at the correct row. The number of days in a billing period can vary from 28, 30, 31, and sometimes even less or more. In my macro, I have it moving down 29 rows to the approximate next cell to enter the “PeriodTotalsFormulas”. On reflection I probably should be putting 30 in there, being 1@28, 4@30 & 7@31. But then again, the sometimes more/less seems to override the pattern here.

Note – I have amended the “PeriodsTotalFormulas” to include a column to show the difference between the Period Total kW hrs and the Invoiced kW hrs Total.

I trust this make the picture clearer for you and look forward to your comments.

Regards
 
Upvote 0
I have been watching this posting but have not commented.
I think it would be best to tell us your overall objective here.
Wanting a script to pause so you can move the cursor and then run some more code and then pause again for the cursor to be moved again is not a good way to do things. And using wait just stops the script from running for a few seconds but you cannot move the cursor during this time.

So again, it would be best to tell us your overall objective without thinking you need to move the cursor. And using select on and on is not the way to write a script.
Like if you want to enter the value "Alpha" into sheet named "Bravo" Range("G1")

All you need to do is write the code like this:

Sheets("Bravo").Range("G1").value="Alpha"

See I selected nothing

But some users think first you have to select or activate the sheet name "Bravo"
Then select Range("G1") and then write code saying selection.value="Alpha"
I would say you have "selected" cell G1 on the sheet "Bravo", and done it with code that does not use the word "select".
That is great, I have learnt something there. But it requires you to nominate/select a definite cell address.
With a lot of the code I write, I do not know the cell address, but I know how to get there using a "railway lines" approach, hence the use of "select".
With regard to my particular problem, I do not know the precise cell address, only know the approximate location and am looking for ways to zero in on the exact desired location. Could it be that there is some way to enter a date and then using the column with consecutive dates in it be taken to desired cell in the row with that date in it?
 
Upvote 0
Well, I can write the script to run whenever you enter a value in column 1 or column 3
Or row 1 or whatever you want

Or I can have the script run when you press a button or do other things.
You tell me what you want to do to cause a script to run. but there is not script I can write that will run when you move the cursor.
 
Upvote 0
Well, I can write the script to run whenever you enter a value in column 1 or column 3
Or row 1 or whatever you want

Or I can have the script run when you press a button or do other things.
You tell me what you want to do to cause a script to run. but there is not script I can write that will run when you move the cursor.
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
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,205
Members
452,618
Latest member
Tam84

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