Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 411
Default How does this code know which sheet to act upon?

Hi,

In a module, modReset, I have the following code. It works on the
proper worksheet, QuotedPart, but I don't understand how it knows
which sheet to act upon.

I want to clear some cells--E2, G2, I2, K2, Q2, R2, S2 & T2--in a
different worksheet, 217, and I'm not clear how to append this code
to accommodate that process.

I certainly appreciate any recommendations.

Thanks,

Dan
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,942
Default How does this code know which sheet to act upon?

hi
unless otherwise specified, vb assumes the code is for the active sheet.

post your code and we might be able to tell you more.

Regards
FSt1

"dan dungan" wrote:

Hi,

In a module, modReset, I have the following code. It works on the
proper worksheet, QuotedPart, but I don't understand how it knows
which sheet to act upon.

I want to clear some cells--E2, G2, I2, K2, Q2, R2, S2 & T2--in a
different worksheet, 217, and I'm not clear how to append this code
to accommodate that process.

I certainly appreciate any recommendations.

Thanks,

Dan

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 411
Default How does this code know which sheet to act upon?

Woops,

I guess I hit send before I was finished.

Sub Clear_Unlocked2()
'Called by cmdReset-clears the unlocked cells
'in range A1:N100 including merged cells

Dim myCell As Range
Application.EnableEvents = False
For Each myCell In Range("A1:N100")
If myCell.Address = "$I$4" Then
'skip it

'ElseIf myCell.Address = "$D$4" Then
'skip it
ElseIf myCell.Locked = False Then
If myCell.MergeCells Then
If myCell.Address = myCell.MergeArea(1).Address Then
myCell.MergeArea.ClearContents
End If
Else
myCell.ClearContents
End If
End If
Next myCell
Range("A6").Select
Selection.End(xlUp).Select
Range("A2:C2").Select
Application.EnableEvents = True
End Sub
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 411
Default How does this code know which sheet to act upon?

I used the following approach which seems to be working.
Private Sub cmdNextPartNum_Click()
'Clears the unlocked cells in Sheets "217" and "A&E,
'range A2:AB2,including merged cells to prepare for next quote
Dim myCell As Range
Application.EnableEvents = False

With Sheets("217")
For Each myCell In Worksheets("217").Range("A2:AB2")
If myCell.Locked = False Then
myCell.ClearContents
End If
Next myCell
End With


With Sheets("A&E")
For Each myCell In Worksheets("A&E").Range("A2:AB2")
If myCell.Locked = False Then
myCell.ClearContents
End If
Next myCell
End With

Worksheets("QuotedPart").Activate
Selection.End(xlUp).Select
CmdNextPartNum.Visible = False
cmdGetPrice.Visible = True
Range("A2:C2").Select
Range("A2:C2").ClearContents

Application.EnableEvents = True
End Sub

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default How does this code know which sheet to act upon?

If you're going to use the with/end with structure, then you don't want this:

With Sheets("217")
For Each myCell In Worksheets("217").Range("A2:AB2")
If myCell.Locked = False Then
myCell.ClearContents
End If
Next myCell
End With

You'd want:

With Sheets("217")
For Each myCell In .Range("A2:AB2")
If myCell.Locked = False Then
myCell.ClearContents
End If
Next myCell
End With

Notice the dot in front of the .range("A2:AB2"). This means that this belongs
to the object in the previous With statement (sheets("217") in your example).

You could have skipped the with/end with, too and used:

For Each myCell In Worksheets("217").Range("A2:AB2")
If myCell.Locked = False Then
myCell.ClearContents
End If
Next myCell

You've got that range("A2:AB2") qualified with the preceding Worksheets("217").

ps. If you have problems with those merged cells, you may want to change:

mycell.clearcontents
to
mycell.value = ""




dan dungan wrote:

I used the following approach which seems to be working.
Private Sub cmdNextPartNum_Click()
'Clears the unlocked cells in Sheets "217" and "A&E,
'range A2:AB2,including merged cells to prepare for next quote
Dim myCell As Range
Application.EnableEvents = False

With Sheets("217")
For Each myCell In Worksheets("217").Range("A2:AB2")
If myCell.Locked = False Then
myCell.ClearContents
End If
Next myCell
End With

With Sheets("A&E")
For Each myCell In Worksheets("A&E").Range("A2:AB2")
If myCell.Locked = False Then
myCell.ClearContents
End If
Next myCell
End With

Worksheets("QuotedPart").Activate
Selection.End(xlUp).Select
CmdNextPartNum.Visible = False
cmdGetPrice.Visible = True
Range("A2:C2").Select
Range("A2:C2").ClearContents

Application.EnableEvents = True
End Sub


--

Dave Peterson


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 411
Default How does this code know which sheet to act upon?

Thanks for your feedback, Dave. I updated the macro with that change.

Dan
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help to code Macro to Copy fron one sheet and paste in other sheet kay Excel Programming 3 July 25th 08 06:46 PM
Code to change code in a sheet and workbook module Otto Moehrbach Excel Programming 11 November 11th 07 07:20 PM
Protect Sheet with code, but then code will not Paste error. How do i get around this. Please read for explainations.... Corey Excel Programming 4 November 25th 06 04:57 AM
Sheet Code Module: copying code to [email protected][_2_] Excel Programming 2 December 14th 04 01:57 AM
excel - macro code to open a protected sheet, enter passowrd, and then protect sheet arunjoshi[_5_] Excel Programming 1 May 2nd 04 03:50 PM


All times are GMT +1. The time now is 06:59 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"