Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Macro VB step required
This is what I am trying to do.
I want an "if" & "then" statement to be inserted in macro (recording) that looks at a particular column and sees if the text "No Error" is present in it. If there is anything in that particular column apart from "No Error" , the macro should NOT run at all. So, just to clarify the above, if there is anything besides "No Error" in that column, the macro should NOT run, otherwise run successfully. Thanks so much |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Macro VB step required
Hi there,
Maybe you're looking for something like this ... Sub MacroConditionalRun() Dim rngFind As Range Set rngFind = Range("A:A").Find("No Error", MatchCase:=True) If Not rngFind Is Nothing Then '... 'run macro here '... End If End Sub Change the column (from A) to that of desired column to look in. HTH -- Regards, Zack Barresse, aka firefytr, (GT = TFS FF Zack) To email, remove the NO SPAM. Please keep correspondence to the board, as to benefit others. "BDANIELLS" wrote in message ... This is what I am trying to do. I want an "if" & "then" statement to be inserted in macro (recording) that looks at a particular column and sees if the text "No Error" is present in it. If there is anything in that particular column apart from "No Error" , the macro should NOT run at all. So, just to clarify the above, if there is anything besides "No Error" in that column, the macro should NOT run, otherwise run successfully. Thanks so much |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Macro VB step required
Thanks ZACK:
Where do I insert this? Thanks "Zack Barresse" wrote: Hi there, Maybe you're looking for something like this ... Sub MacroConditionalRun() Dim rngFind As Range Set rngFind = Range("A:A").Find("No Error", MatchCase:=True) If Not rngFind Is Nothing Then '... 'run macro here '... End If End Sub Change the column (from A) to that of desired column to look in. HTH -- Regards, Zack Barresse, aka firefytr, (GT = TFS FF Zack) To email, remove the NO SPAM. Please keep correspondence to the board, as to benefit others. "BDANIELLS" wrote in message ... This is what I am trying to do. I want an "if" & "then" statement to be inserted in macro (recording) that looks at a particular column and sees if the text "No Error" is present in it. If there is anything in that particular column apart from "No Error" , the macro should NOT run at all. So, just to clarify the above, if there is anything besides "No Error" in that column, the macro should NOT run, otherwise run successfully. Thanks so much |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Macro VB step required
You can copy the code I posted and paste it into your Visual Basic Editor
(VBE) in a Standard Module located in your project (workbook). Shortcut keys would be .. Alt + F11 (open VBE) Ctrl + R (open Project Explorer) Select file on left If no modules exist: Insert | Module Paste code in Module If modules exist: Double click desired module Paste code in Module Add code as desired Is there other code you would like help with here? -- Regards, Zack Barresse, aka firefytr, (GT = TFS FF Zack) To email, remove the NO SPAM. Please keep correspondence to the board, as to benefit others. "BDANIELLS" wrote in message ... Thanks ZACK: Where do I insert this? Thanks "Zack Barresse" wrote: Hi there, Maybe you're looking for something like this ... Sub MacroConditionalRun() Dim rngFind As Range Set rngFind = Range("A:A").Find("No Error", MatchCase:=True) If Not rngFind Is Nothing Then '... 'run macro here '... End If End Sub Change the column (from A) to that of desired column to look in. HTH -- Regards, Zack Barresse, aka firefytr, (GT = TFS FF Zack) To email, remove the NO SPAM. Please keep correspondence to the board, as to benefit others. "BDANIELLS" wrote in message ... This is what I am trying to do. I want an "if" & "then" statement to be inserted in macro (recording) that looks at a particular column and sees if the text "No Error" is present in it. If there is anything in that particular column apart from "No Error" , the macro should NOT run at all. So, just to clarify the above, if there is anything besides "No Error" in that column, the macro should NOT run, otherwise run successfully. Thanks so much |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Macro VB step required
I would like to call you and ask you where exactly i should do this. There
are 9 modules of which 8 are blank. The 9th one has the code in it. Do you want me to copy it there? "Zack Barresse" wrote: You can copy the code I posted and paste it into your Visual Basic Editor (VBE) in a Standard Module located in your project (workbook). Shortcut keys would be .. Alt + F11 (open VBE) Ctrl + R (open Project Explorer) Select file on left If no modules exist: Insert | Module Paste code in Module If modules exist: Double click desired module Paste code in Module Add code as desired Is there other code you would like help with here? -- Regards, Zack Barresse, aka firefytr, (GT = TFS FF Zack) To email, remove the NO SPAM. Please keep correspondence to the board, as to benefit others. "BDANIELLS" wrote in message ... Thanks ZACK: Where do I insert this? Thanks "Zack Barresse" wrote: Hi there, Maybe you're looking for something like this ... Sub MacroConditionalRun() Dim rngFind As Range Set rngFind = Range("A:A").Find("No Error", MatchCase:=True) If Not rngFind Is Nothing Then '... 'run macro here '... End If End Sub Change the column (from A) to that of desired column to look in. HTH -- Regards, Zack Barresse, aka firefytr, (GT = TFS FF Zack) To email, remove the NO SPAM. Please keep correspondence to the board, as to benefit others. "BDANIELLS" wrote in message ... This is what I am trying to do. I want an "if" & "then" statement to be inserted in macro (recording) that looks at a particular column and sees if the text "No Error" is present in it. If there is anything in that particular column apart from "No Error" , the macro should NOT run at all. So, just to clarify the above, if there is anything besides "No Error" in that column, the macro should NOT run, otherwise run successfully. Thanks so much |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
Macro VB step required
Zack: This is what module 9 looks like:
' ' FINAL Macro Sub MacroConditionalRun() Dim rngFind As Range Set rngFind = Range("Y:Y").Find("No Error", MatchCase:=True) If Not rngFind Is Nothing Then ' Sheets("TX Shuttle").Select Rows("3:3").Select Range(Selection, Selection.End(xlDown)).Select Range(Selection, Selection.End(xlDown)).Select Selection.Delete Shift:=xlUp Rows("2:2").Select Selection.Copy Rows("3:6758").Select ActiveSheet.Paste Selection.AutoFilter Field:=1, Criteria1:="STOP" Rows("37:37").Select Range(Selection, Selection.End(xlDown)).Select Application.CutCopyMode = False Selection.Delete Shift:=xlUp Selection.AutoFilter Field:=1 Range("C8").Select ActiveWindow.SmallScroll Down:=-27 Sheets("GL Entry").Select ActiveWorkbook.Save End If End Sub Remember, i want it to STOP if it sees something other than "No Error" in column J. Also I want it to message me "Please correct ALL errors before running final script". Thanks so much! |
#7
Posted to microsoft.public.excel.programming
|
|||
|
|||
Macro VB step required
Hey, yeah you can call me if you'd like. Whatever works easiest for you.
Email me (remove the nospam) and we'll get that going. I have an untested version of code that may work. I dont' have your workbook and/or data structure to test it on ... Option Explicit Sub MacroConditionalRun() Dim rngFind As Range Set rngFind = Range("Y:Y").Find("No Error", MatchCase:=True) If Not rngFind Is Nothing Then With Sheets("TX Shuttle") With .Rows("3:3") .Range(Range(.Address, .End(xlDown)), .End(xlDown)).Delete End With .Rows("2:2").Copy Destination:=.Rows("3:6758") If IsFilterOn(.Name) Then .Cells.AutoFilter .Rows("3:6758").AutoFilter Field:=1, Criteria1:="STOP" .Range(.Rows("37:37"), .Rows("37:37").End(xlDown)).Delete If IsFilterOn(.Name) Then .Cells.AutoFilter .Rows("37:37").AutoFilter Field:=1 End With Sheets("GL Entry").Activate ' ActiveWorkbook.Save End If End Sub Function IsFilterOn(ws As String, Optional wb As String) As Boolean If wb = "" Then wb = ActiveWorkbook.Name If Workbooks(wb).Sheets(ws).AutoFilterMode Then IsFilterOn = True End Function Two things of real significance here. First is I commented out your Save. That is so you can run your code and then check to see if it performed the way you wanted it to without having to save over any unecessary/unwanted changed. This works best if you save prior to running the routine. The second is the IsFilterOn function. In VBA, if you try to set the autofilter method on a range of cells and it is already running, it will produce an error. For better error handling, I've added the function to check it for you. And if it's on, then it will take it off as so you can apply it again. HTH -- Regards, Zack Barresse, aka firefytr, (GT = TFS FF Zack) To email, remove the NO SPAM. Please keep correspondence to the board, as to benefit others. "BDANIELLS" wrote in message ... Zack: This is what module 9 looks like: ' ' FINAL Macro Sub MacroConditionalRun() Dim rngFind As Range Set rngFind = Range("Y:Y").Find("No Error", MatchCase:=True) If Not rngFind Is Nothing Then ' Sheets("TX Shuttle").Select Rows("3:3").Select Range(Selection, Selection.End(xlDown)).Select Range(Selection, Selection.End(xlDown)).Select Selection.Delete Shift:=xlUp Rows("2:2").Select Selection.Copy Rows("3:6758").Select ActiveSheet.Paste Selection.AutoFilter Field:=1, Criteria1:="STOP" Rows("37:37").Select Range(Selection, Selection.End(xlDown)).Select Application.CutCopyMode = False Selection.Delete Shift:=xlUp Selection.AutoFilter Field:=1 Range("C8").Select ActiveWindow.SmallScroll Down:=-27 Sheets("GL Entry").Select ActiveWorkbook.Save End If End Sub Remember, i want it to STOP if it sees something other than "No Error" in column J. Also I want it to message me "Please correct ALL errors before running final script". Thanks so much! |
#8
Posted to microsoft.public.excel.programming
|
|||
|
|||
Macro VB step required
Zack: Can you call me @ 281 798 7808 or I can call you
Sorry for being so clueless about this Thanks Brian "Zack Barresse" wrote: Hey, yeah you can call me if you'd like. Whatever works easiest for you. Email me (remove the nospam) and we'll get that going. I have an untested version of code that may work. I dont' have your workbook and/or data structure to test it on ... Option Explicit Sub MacroConditionalRun() Dim rngFind As Range Set rngFind = Range("Y:Y").Find("No Error", MatchCase:=True) If Not rngFind Is Nothing Then With Sheets("TX Shuttle") With .Rows("3:3") .Range(Range(.Address, .End(xlDown)), .End(xlDown)).Delete End With .Rows("2:2").Copy Destination:=.Rows("3:6758") If IsFilterOn(.Name) Then .Cells.AutoFilter .Rows("3:6758").AutoFilter Field:=1, Criteria1:="STOP" .Range(.Rows("37:37"), .Rows("37:37").End(xlDown)).Delete If IsFilterOn(.Name) Then .Cells.AutoFilter .Rows("37:37").AutoFilter Field:=1 End With Sheets("GL Entry").Activate ' ActiveWorkbook.Save End If End Sub Function IsFilterOn(ws As String, Optional wb As String) As Boolean If wb = "" Then wb = ActiveWorkbook.Name If Workbooks(wb).Sheets(ws).AutoFilterMode Then IsFilterOn = True End Function Two things of real significance here. First is I commented out your Save. That is so you can run your code and then check to see if it performed the way you wanted it to without having to save over any unecessary/unwanted changed. This works best if you save prior to running the routine. The second is the IsFilterOn function. In VBA, if you try to set the autofilter method on a range of cells and it is already running, it will produce an error. For better error handling, I've added the function to check it for you. And if it's on, then it will take it off as so you can apply it again. HTH -- Regards, Zack Barresse, aka firefytr, (GT = TFS FF Zack) To email, remove the NO SPAM. Please keep correspondence to the board, as to benefit others. "BDANIELLS" wrote in message ... Zack: This is what module 9 looks like: ' ' FINAL Macro Sub MacroConditionalRun() Dim rngFind As Range Set rngFind = Range("Y:Y").Find("No Error", MatchCase:=True) If Not rngFind Is Nothing Then ' Sheets("TX Shuttle").Select Rows("3:3").Select Range(Selection, Selection.End(xlDown)).Select Range(Selection, Selection.End(xlDown)).Select Selection.Delete Shift:=xlUp Rows("2:2").Select Selection.Copy Rows("3:6758").Select ActiveSheet.Paste Selection.AutoFilter Field:=1, Criteria1:="STOP" Rows("37:37").Select Range(Selection, Selection.End(xlDown)).Select Application.CutCopyMode = False Selection.Delete Shift:=xlUp Selection.AutoFilter Field:=1 Range("C8").Select ActiveWindow.SmallScroll Down:=-27 Sheets("GL Entry").Select ActiveWorkbook.Save End If End Sub Remember, i want it to STOP if it sees something other than "No Error" in column J. Also I want it to message me "Please correct ALL errors before running final script". Thanks so much! |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Creating a Drop Down List with Step by Step Instructions for 2007 | Excel Worksheet Functions | |||
Macro Step by Step | Excel Discussion (Misc queries) | |||
running macro step by step different from normal run?? | Excel Programming | |||
I need step by step instructions to create a macro for 10 imbedde. | Excel Worksheet Functions | |||
VBA macro step-by-step | Excel Programming |