ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   How to create a routine (https://www.excelbanter.com/excel-discussion-misc-queries/40067-how-create-routine.html)

Tara

How to create a routine
 
I would like to have a routine that would put data (an X) in cells at the
start of a day, so that as I then check the item each day and update the
contents of other cells, I can remove the X? It would only do this at the
start of a new day. The worksheet might be opened several different times.

Dave Peterson

I bet you could do something like this. But what happens when you get
interrupted and have to start over. If your routine actually keeps track, you
may not be able to reset your data.

How about an alternative. Just have a macro that you can run on demand. Run it
whenever you want (usually the first time you open the workbook that day).

Say your X's go in column A starting in Row 2 and continues until you run out of
data in column B.

You could use something like:

Option Explicit
Sub AddXs()

Dim wks As Worksheet
Dim FirstRow As Long
Dim LastRow As Long

Set wks = Worksheets("Sheet1")

With wks
FirstRow = 2
LastRow = .Cells(.Rows.Count, "B").End(xlUp).Row

.Range(.Cells(FirstRow, "A"), .Cells(LastRow, "A")).Value = "X"
End With

End Sub

Then you could run it by:
tools|macro|macros|select the name of the macro (AddXs)
click run



Tara wrote:

I would like to have a routine that would put data (an X) in cells at the
start of a day, so that as I then check the item each day and update the
contents of other cells, I can remove the X? It would only do this at the
start of a new day. The worksheet might be opened several different times.


--

Dave Peterson


All times are GMT +1. The time now is 12:06 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com