Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-28-2014, 07:34 AM
BobBridges's Avatar
BobBridges BobBridges is offline Code to send cursor to predefined cell Windows 7 64bit Code to send cursor to predefined cell Office 2010 32bit
Expert
 
Join Date: May 2013
Location: USA
Posts: 700
BobBridges has a spectacular aura aboutBobBridges has a spectacular aura about
Default

It's me again, Keith. Do you want this to execute in every worksheet of workbook, or only in a particular worksheet? I ask because for both solutions you'll write approximately the same program, but if it's to operate on only a particular worksheet then you'll store it in the "Excel Object" that corresponds to that worksheet, but if in every worksheet then you'll put it in the ThisWorkbook object. You can see those in your VBA editor under "Microsoft Excel Objects" rather than "Modules".



(And by the way I'm assuming that you already know something about the VBA editor. If you don't—if this'll be your first macro—I should back up and start at the beginning.)

The macro you write will be named "Worksheet_Change"—it must have that exact name, because that way you cause it to respond to an event with that exact name—and it has to have the prescribed list of arguments with exactly the right data types, though each argument can be named what you choose. All this is defined here; take a look. Within those limitations your macro can do whatever you like.

I have a short Worksheet_Change macro that looks like this:
Code:
Private Sub Worksheet_Change(ByVal Tgt As Excel.Range)
  If Cells(1, Tgt.Column).Value <> "From" Then Exit Sub
  Set co = Cells(Tgt.Row, 1)

  ' If there's already a date there, it'd better be today's.
  vd = co.Value
  If Not IsEmpty(vd) Then
    If vd <> Date Then Abend "Not today's date."
    End If

  ' Otherwise make it so.
  co.Value = Date

  End Sub
This goes in a timesheet I maintain. Whenever I enter a value in one of the columns headed "From", it put's today's date in the date column. If it already had today's date in that cell, fine; but if it had some other date (in case I made a mistake) it displays a warning message. That's all it does. Maybe you can use it as a sort of template.
Reply With Quote
  #2  
Old 10-30-2014, 02:07 AM
htieK htieK is offline Code to send cursor to predefined cell Windows 7 32bit Code to send cursor to predefined cell Office 2010 32bit
Novice
Code to send cursor to predefined cell
 
Join Date: Oct 2014
Posts: 9
htieK is on a distinguished road
Default

Sorry Bob, have been away. Will look at this tomorrow! - Keith
Reply With Quote
Reply

Tags
send cursor, vba code



Similar Threads
Thread Thread Starter Forum Replies Last Post
Code to send cursor to predefined cell VBA code to select one word from a text in a cell and place that word in next cell Shinaj Excel 2 05-01-2014 01:50 PM
Macro code should find inv no in folder and send attachhed mail. visha_1984 Outlook 0 01-30-2013 05:08 AM
Displaying cursor position within cell MiamiTom Excel 0 11-18-2011 09:02 AM
Code to send cursor to predefined cell Code for Changing Cell Backgrounds leroytrolley Excel 2 12-05-2008 02:05 AM
Code to send cursor to predefined cell code to save / rename / send attachments unit213 Outlook 1 09-26-2007 08:15 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 09:36 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft