Solved

Excel Spreadsheet Macro Question

Posted on 2002-04-05
6
370 Views
Last Modified: 2008-03-17
I have a Macro that copies range I9:I22 from each sheet and pastes it to a summary sheet. The macro works great but when i go back to each sheet where the macro selected that range those cells are still black or selected. How do you write code into my macro to Unselect or unblacken those cells on each sheet?
Here is a copy of my macro.....

Sub Total_Hours()
Application.ScreenUpdating = False
Dim timesheet As Worksheet
    Dim Cell As Range
     For Each timesheet In ActiveWorkbook.Worksheets
        timesheet.Select
        Range("i9:i22").Select
        Selection.Copy
        Worksheets("total_hours").Activate
        ActiveCell.Offset(0, 1).PasteSpecial Paste:=xlValues
        Application.CutCopyMode = False
    Next
    Range("b1").Select
   
End Sub
0
Comment
Question by:He4Giv
6 Comments
 
LVL 32

Expert Comment

by:bhess1
ID: 6922115
Try Range(I9:i9).Activate - this should cancel the selection, and set the active cell to the top of the range.
0
 

Author Comment

by:He4Giv
ID: 6922292
That didnt work...Range("i9:i20").activate still shows that range on each worksheet as selected.
0
 
LVL 1

Accepted Solution

by:
nikelsh earned 50 total points
ID: 6922326
i thought after pasting u have to go again on the main sheet and select one of the cell. ie.

Sub Total_Hours()
Application.ScreenUpdating = False
Dim timesheet As Worksheet
   Dim Cell As Range
    For Each timesheet In ActiveWorkbook.Worksheets
       timesheet.Select
       Range("i9:i22").Select
       Selection.Copy
       Worksheets("total_hours").Activate
       ActiveCell.Offset(0, 1).PasteSpecial Paste:=xlValues
       Application.CutCopyMode = False
       timesheet.Select  ' select again
       Range("b1").Select ' any one cell in this sheet
   Next
   Range("b1").Select
     
End Sub

hope this will help u.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6922328
Try this:
Sub Total_Hours()
Application.ScreenUpdating = False
Dim timesheet As Worksheet
   Dim Cell As Range
    For Each timesheet In ActiveWorkbook.Worksheets
       with timesheet
            .Select
            .Range("i9:i22").Select
            Selection.Copy
            Worksheets("total_hours").Activate
            ActiveCell.Offset(0, 1).PasteSpecial Paste:=xlValues
           Application.CutCopyMode = False
           .range("A1").select
       End With
   Next
   Range("b1").Select
   
End Sub
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6922330
oops!
Sorry...
....
.....
....
False
          .range("A1").Activate
      End With
  Next
  Range("b1").Select
 
End Sub
0
 

Author Comment

by:He4Giv
ID: 6922877
Works Great!!

Thank You
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now