Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default Macro running halfway only

HI,

I have this sub that runs only if I am on the worksheet "OSMI matches".
Is there a way I can modify it so that it is not sensitive to which
worksheet I am on when I try to run it (using the assigned shortcut
key) ? As of now, if I am on another worksheet, it runs until it hits
the data validation part, and then it just stops, giving the error box
"400". I am really confused .. here is the relevent part of the code:

Sub FOSMITRED()

Dim SHS As Worksheet
Dim SHD As Worksheet
Dim c, d As Range
Dim i, j As Variant

Set SHS = Worksheets("rawresults")
Set SHD = Worksheets("OSMI matches")

Set c = SHD.Cells(1, 1)
Set d = SHS.Cells(1, 2)

i = 1
j = 1



Application.ScreenUpdating = False


'reads results from FOSMIT file into rawresults
Call dataread


'Go through column A of OSMI matches worksheet; stop at the first empty
cell;
'Assign i as the row index of that cell
Do While Not IsEmpty(c)
i = i + 1
Set c = c.Offset(1, 0)
Loop


'Fill asterisks in row i and date in row (i+1)
'Define column J in results as "status"
SHD.Range(SHD.Cells(i, 1), SHD.Cells(i, 9)).FormulaR1C1 = "****"
SHD.Cells((i + 1), 1).FormulaR1C1 = "Date & day: "
SHD.Cells((i + 2), 10).FormulaR1C1 = "Status"

'Enter data validation property for date and day ----- PROGRAM RUNS
TILL HERE ----
SHD.Cells(i + 1, "B").Select
With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop,
Operator:= _
xlBetween, Formula1:="=Month"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
SHD.Cells(i + 1, 3).Select
With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop,
Operator:= _
xlBetween, Formula1:="=Date"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
SHD.Cells(i + 1, 4).Select
With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop,
Operator:= _
xlBetween, Formula1:="=Year"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With


Thanks in advance,

Joe.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,081
Default Macro running halfway only

the code stops because you're trying to select a range on a sheet that is NOT
active.

The good news is you don't need to select the ranges on which you are
acting. If you assign the range you're trying to select to a range variable,
you should be ok

dim rng as Range
set rng = SHD.Cells(i + 1, "B")
with rng.validation
etc




"Joe" wrote:

HI,

I have this sub that runs only if I am on the worksheet "OSMI matches".
Is there a way I can modify it so that it is not sensitive to which
worksheet I am on when I try to run it (using the assigned shortcut
key) ? As of now, if I am on another worksheet, it runs until it hits
the data validation part, and then it just stops, giving the error box
"400". I am really confused .. here is the relevent part of the code:

Sub FOSMITRED()

Dim SHS As Worksheet
Dim SHD As Worksheet
Dim c, d As Range
Dim i, j As Variant

Set SHS = Worksheets("rawresults")
Set SHD = Worksheets("OSMI matches")

Set c = SHD.Cells(1, 1)
Set d = SHS.Cells(1, 2)

i = 1
j = 1



Application.ScreenUpdating = False


'reads results from FOSMIT file into rawresults
Call dataread


'Go through column A of OSMI matches worksheet; stop at the first empty
cell;
'Assign i as the row index of that cell
Do While Not IsEmpty(c)
i = i + 1
Set c = c.Offset(1, 0)
Loop


'Fill asterisks in row i and date in row (i+1)
'Define column J in results as "status"
SHD.Range(SHD.Cells(i, 1), SHD.Cells(i, 9)).FormulaR1C1 = "****"
SHD.Cells((i + 1), 1).FormulaR1C1 = "Date & day: "
SHD.Cells((i + 2), 10).FormulaR1C1 = "Status"

'Enter data validation property for date and day ----- PROGRAM RUNS
TILL HERE ----
SHD.Cells(i + 1, "B").Select
With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop,
Operator:= _
xlBetween, Formula1:="=Month"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
SHD.Cells(i + 1, 3).Select
With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop,
Operator:= _
xlBetween, Formula1:="=Date"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
SHD.Cells(i + 1, 4).Select
With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop,
Operator:= _
xlBetween, Formula1:="=Year"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With


Thanks in advance,

Joe.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27
Default Macro running halfway only

Thank you very much. I shall try that - assigning ranges.

Joe.

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
how do you make a line of a chart change color halfway through? biff Charts and Charting in Excel 8 April 3rd 23 01:13 PM
disable user running macro from Tools Macro Steve Simons Excel Discussion (Misc queries) 4 September 28th 06 06:28 AM
Halfway to End Rokuro kubi Excel Discussion (Misc queries) 8 September 26th 06 05:30 PM
if month is less than halfway over subtract 1 coal_miner Excel Worksheet Functions 3 May 4th 05 03:57 PM
Launch Macro in Access via Macro running in Excel??? dgrant Excel Programming 1 September 24th 03 01:38 PM


All times are GMT +1. The time now is 10:08 AM.

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

About Us

"It's about Microsoft Excel"