Computing.Net > Forums > Office Software > writing macros

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

writing macros

Reply to Message Icon

Name: tvonbehren
Date: June 25, 2009 at 11:42:45 Pacific
OS: Windows XP
Subcategory: Microsoft Office
Comment:

I need to know how to do if the columns and rows are different between the sheets. For instance sheet 1 date at A1 and need to have copy on sheet 2 at D8, and then sheet 2s D8 back to sheet 1s A1 and I am needing to do this to more than just 1 cell needing multiple cell like this. This is what was given to me and it works really well but is not exactly what i need.
Sub Worksheet_SelectionChange(ByVal Target As Range)
Set myRange = Range("A1,B3,C5")
If Not Intersect(Target, myRange) Is Nothing Then
myDate = Application.InputBox("Enter A Date", "Date Entry")
Sheets(1).Range(Target.Address) = myDate
Sheets(2).Range(Target.Address) = myDate
End If
End Sub



Sponsored Link
Ads by Google

Response Number 1
Name: DerbyDad03
Date: June 25, 2009 at 14:46:49 Pacific
Reply:

This is a continuation of your earlier thread and should not be in thread by itself.


0

Response Number 2
Name: tvonbehren
Date: June 25, 2009 at 15:28:22 Pacific
Reply:

yes, I really appreciate the help and sorry not used to this forum. but would appreciate any more help you could give and again thanks in advance.


0

Response Number 3
Name: DerbyDad03
Date: June 25, 2009 at 19:24:23 Pacific
Reply:

Unless there is some pattern that is associated with the cell pairings in question, such as the same number of rows and columns offset from the cells in one sheet to the cells in the other, you would need to hard code each individual pairing.

In Sheet1 you might put something like this:

Sub Worksheet_SelectionChange(ByVal Target As Range)
 If Target.Address = "$A$1" Then
   myDate = Application.InputBox("Enter A Date", "Date Entry")
    Sheets(1).Range(Target.Address) = myDate
    Sheets(2).Range("$D$8") = myDate
 End If
 If Target.Address = "$B$5" Then
   myDate = Application.InputBox("Enter A Date", "Date Entry")
    Sheets(1).Range(Target.Address) = myDate
    Sheets(2).Range("$F$3") = myDate
 End If
 If Target.Address = "$C$2" Then
   myDate = Application.InputBox("Enter A Date", "Date Entry")
    Sheets(1).Range(Target.Address) = myDate
    Sheets(2).Range("$B$4") = myDate
 End If
End Sub

In Sheet2, you would reverse each pairing. e.g.

 If Target.Address = "$D$8" Then
   myDate = Application.InputBox("Enter A Date", "Date Entry")
    Sheets(2).Range(Target.Address) = myDate
    Sheets(1).Range("$A$1") = myDate
 End If

Another option, which actually might be more efficient, is to use Select Case. Again, you would need a copy of this code in both sheets, with the pairings reversed.

Sub Worksheet_SelectionChange(ByVal Target As Range)
 Select Case Target.Address

   Case "$A$1"
     myDate = Application.InputBox("Enter A Date", "Date Entry")
      Sheets(1).Range(Target.Address) = myDate
      Sheets(2).Range("$D$8") = myDate
    
   Case "$B$5"
     myDate = Application.InputBox("Enter A Date", "Date Entry")
      Sheets(1).Range(Target.Address) = myDate
      Sheets(2).Range("$F$3") = myDate
   
   Case "$C$2"
     myDate = Application.InputBox("Enter A Date", "Date Entry")
      Sheets(1).Range(Target.Address) = myDate
      Sheets(2).Range("$B$4") = myDate

 End Select
End Sub


0

Response Number 4
Name: tvonbehren
Date: June 26, 2009 at 04:11:05 Pacific
Reply:

Thak you sir very much. This is exactly what I was needing and will help out tremendously


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Panasonic Kx-p1180 need a macro or vba code ...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Office Software Forum Home


Sponsored links

Ads by Google


Results for: writing macros

Need help writing Excel Macro www.computing.net/answers/office/need-help-writing-excel-macro/6792.html

Macro in Excel www.computing.net/answers/office/macro-in-excel/5048.html

Macros MS Word www.computing.net/answers/office/macros-ms-word/7446.html