ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Help linking true false in column to start macros (https://www.excelbanter.com/excel-discussion-misc-queries/447551-help-linking-true-false-column-start-macros.html)

jt24152

Help linking true false in column to start macros
 
Hi,
I have been trying to get a macros to run based on the value of a cell in Column D.
What I would like it to do. Look down through column "D" when the value of the cell is true perform a macros (which i have created). It has to recognize that the cell with the value of true is the "Activecell" as my macros is setup for active cell.
My code looks like this so far
Sub MacrosTest()
'
'
Selection.End(xlToLeft).Select
Selection.End(xlToLeft).Select
ActiveCell.Range("A1:C1").Select
Selection.Copy
Sheets("Blank Stickers").Select
Selection.End(xlDown).Select
Selection.End(xlUp).Select
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveCell.Select
ActiveSheet.Paste
Sheets("File").Select
ActiveCell.Select

End Sub

The Names of the sheets a
File
Blank Stickers

jack_n_bub

Quote:

Originally Posted by jt24152 (Post 1606979)
Hi,
I have been trying to get a macros to run based on the value of a cell in Column D.
What I would like it to do. Look down through column "D" when the value of the cell is true perform a macros (which i have created). It has to recognize that the cell with the value of true is the "Activecell" as my macros is setup for active cell.
My code looks like this so far
Sub MacrosTest()
'
'
Selection.End(xlToLeft).Select
Selection.End(xlToLeft).Select
ActiveCell.Range("A1:C1").Select
Selection.Copy
Sheets("Blank Stickers").Select
Selection.End(xlDown).Select
Selection.End(xlUp).Select
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveCell.Select
ActiveSheet.Paste
Sheets("File").Select
ActiveCell.Select

End Sub

The Names of the sheets a
File
Blank Stickers

Hi,

Try this.

Sub CheckForsomething()
Range("D1").Activate
Do While ActiveCell.Value < ""
If ActiveCell.Value = True Then Call Macrotest
ActiveCell.Offset(1, 0).Activate
Loop
End Sub

This code will start from Range D1 and will keep looking in column D until there is either an empty cell or the value of the cell is True.

If the value of cell is true this will call your procedure (macrotest).

Instead of calling the macro you may like to substitute your code in my procedure. Either ways, your purpose should be complete.

Let me know if it helps.

Thanks,
Prashant

jt24152

Quote:

Originally Posted by jack_n_bub (Post 1606995)
Hi,

Try this.

Sub CheckForsomething()
Range("D1").Activate
Do While ActiveCell.Value < ""
If ActiveCell.Value = True Then Call Macrotest
ActiveCell.Offset(1, 0).Activate
Loop
End Sub

This code will start from Range D1 and will keep looking in column D until there is either an empty cell or the value of the cell is True.

If the value of cell is true this will call your procedure (macrotest).

Instead of calling the macro you may like to substitute your code in my procedure. Either ways, your purpose should be complete.

Let me know if it helps.

Thanks,
Prashant

Well. It is doing something but not what i would have hoped.
Currently it runs clear down my list of numbers but it is still only performing the macros of copy pasting from the current sheet (File) to the other sheet (Blank Stickers) in the row of the active cell at which i have selected prior to runs the macros. It doesn't seem to be looking for true/false/blank in column "D". Frustrating.
Any other ideas?

jack_n_bub

Quote:

Originally Posted by jt24152 (Post 1607018)
Well. It is doing something but not what i would have hoped.
Currently it runs clear down my list of numbers but it is still only performing the macros of copy pasting from the current sheet (File) to the other sheet (Blank Stickers) in the row of the active cell at which i have selected prior to runs the macros. It doesn't seem to be looking for true/false/blank in column "D". Frustrating.
Any other ideas?

Hi,

Is it fine for you to share a sample. As told earlier, there are better ways to perform your task but I provided the solution as per your requirement.

I can look into your code and make necessary corrections and send it back to you.

By the way, you need to run my macro after you have activated the sheet which has column D you are checking for. And I am also assuming that the keyword True is a logical value not a text, i.e. not "TRUE" but TRUE (logical value).

Thanks,
Prashant

jt24152

Quote:

Originally Posted by jack_n_bub (Post 1607019)
Hi,

Is it fine for you to share a sample. As told earlier, there are better ways to perform your task but I provided the solution as per your requirement.

I can look into your code and make necessary corrections and send it back to you.

By the way, you need to run my macro after you have activated the sheet which has column D you are checking for. And I am also assuming that the keyword True is a logical value not a text, i.e. not "TRUE" but TRUE (logical value).

Thanks,
Prashant

Ok. I am trying to attach it but having difficulties.
I found this online an it works to find the first true in column D but wont loop.

jt24152

Quote:

Originally Posted by jt24152 (Post 1607020)
Ok. I am trying to attach it but having difficulties.
I found this online an it works to find the first true in column D but wont loop.

Sub Test3()
Dim x As String
Dim found As Boolean
' Select first line of data.
Range("D1").Select
' Set search variable value.
x = True
' Set Boolean variable "found" to false.
found = False
' Set Do loop to stop at empty cell.
Do Until IsEmpty(ActiveCell)
' Check active cell for search value.
If ActiveCell.Value = x Then
found = True
Exit Do
End If
' Step down 1 row from present location.
ActiveCell.Offset(1, 0).Select
Loop
' Check for found.
If found = True Then
MsgBox "Value found in cell " & ActiveCell.Address
Else
MsgBox "Value not found"
End If
End Sub

jt24152

1 Attachment(s)
Quote:

Originally Posted by jt24152 (Post 1607021)
Sub Test3()
Dim x As String
Dim found As Boolean
' Select first line of data.
Range("D1").Select
' Set search variable value.
x = True
' Set Boolean variable "found" to false.
found = False
' Set Do loop to stop at empty cell.
Do Until IsEmpty(ActiveCell)
' Check active cell for search value.
If ActiveCell.Value = x Then
found = True
Exit Do
End If
' Step down 1 row from present location.
ActiveCell.Offset(1, 0).Select
Loop
' Check for found.
If found = True Then
MsgBox "Value found in cell " & ActiveCell.Address
Else
MsgBox "Value not found"
End If
End Sub

Ok I have attached a sample of what I hav been trying to do. Hope this helps

jt24152

So your formula works great now that I moved the True/False to column "A"

The only other think is my Macros I created to copy and paste from Sheet1 to sheet2 stops with an error and will not continue to loop the checkforsomething.

Any ideas on how to fix it so after my macros is finished that it continues on with the one you gave me?
Here is my code
Sub Move()
'
' Move Macro
'

'
Selection.End(xlToLeft).Select
Selection.End(xlToLeft).Select
ActiveCell.Offset(0, 1).Range("A1:C1").Select
Selection.Copy
Sheets("BlankStickers").Select
ActiveCell.Offset(-2, 0).Range("A1").Select
Selection.End(xlDown).Select
Selection.End(xlDown).Select
Selection.End(xlUp).Select
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveSheet.Paste
Sheets("File").Select
End Sub


It stops on Sheets("File").Select


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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com