In VBA: Trigger a Macro for a row when a specific cell updates - without having to highlight the specific row

ECKSELL

New Member
Joined
Feb 28, 2008
Messages
9
Hi,
I kindly ask for help with the following please:

The 3 Macros below can be triggered individually using 3 buttons IF you highlight a specific ROW, (for example having focus on the Cell A11) - and then click on any of the 3 individual macro buttons to execute any of the 3 macros individually. I would like to continue to use this behavior – but also combine this with a more automatic approach where:

IF cell A1 in the Sheet named (“Sheet1) contains the value 1 => Then (in the Sheet named “Orders”) automatically trigger the 1st Marco named “placeOrder” for the specific row No 11
IF cell A1 in the Sheet named (“Sheet1) contains the value 2 => Then (in the Sheet named “Orders”) automatically trigger the 2nd Marco named “cancelOrder” for the specific row No 11
IF cell A1 in the Sheet named (“Sheet1) contains the value 3 => Then (in the Sheet named “Orders”) automatically trigger the 3rd Marco named “clearOrder” for the specific row No 11
IF cell A1 in the Sheet named (“Sheet2) contains the value 1 => Then (in the Sheet named “Orders”) automatically trigger the 1st Marco named “placeOrder” for the specific row No 12
IF cell A1 in the Sheet named (“Sheet2) contains the value 2 => Then (in the Sheet named “Orders”) automatically trigger the 2nd Marco named “cancelOrder” for the specific row No 12
IF cell A1 in the Sheet named (“Sheet2) contains the value 3 => Then (in the Sheet named “Orders”) automatically trigger the 3rd Marco named “clearOrder” for the specific row No 12

Ideally I would like to update the 3 Macros individual - so that I can decide IF I would like to use the “standard” approach to execute the macros individually for the “rows” I decide to click on, OR in case for example Cell A1 in the “Sheet2”contains the Value “2” – then the macro “cancelOrder” should be triggered automatically in the Sheet “Orders”

Thanks, and the VBA code is below:


' ========================================================
' place order for active row
' ========================================================
Sub placeOrder()
Dim row As Range, server As String, lastRowIndex As Integer

server = util.getServerVal(STR_SHEET_NAME, CELL_SERVER_NAME)
If server = util.STR_EMPTY Then Exit Sub

For Each row In Selection.rows
lastRowIndex = row.row
If Not util.hasContractData(Worksheets(STR_SHEET_NAME), dataStartRowIndex, row, startOfContractColumns, getContractColumns()) Then GoTo Continue
sendPlaceOrder server, row

Continue:
Next row

Worksheets(STR_SHEET_NAME).Cells(lastRowIndex, 1).offset(0, 0).Activate

End Sub

' ========================================================
' cancel order for active row
' ========================================================
Sub cancelOrder()
Dim server As String, id As String, i As Integer, row As Range, lastRowIndex As Integer

server = util.getServerVal(STR_SHEET_NAME, CELL_SERVER_NAME)
If server = util.STR_EMPTY Then Exit Sub

With Worksheets(STR_SHEET_NAME)
For Each row In Selection.rows
lastRowIndex = row.row
If .Cells(row.row, idColumnIndex).value = STR_EMPTY Then GoTo Continue
If Not util.hasContractData(Worksheets(STR_SHEET_NAME), dataStartRowIndex, row, startOfContractColumns, getContractColumns()) Then GoTo Continue

id = .Cells(row.row, idColumnIndex).value
util.sendRequest server, STR_CANCELORDER, id

Continue:
Next row

.Cells(lastRowIndex, 1).offset(0, 0).Activate

End With

End Sub

' ========================================================
' clear order for active row
' ========================================================
Sub clearOrder()
Dim server As String, id As String, i As Integer, row As Range, lastRowIndex As Integer

server = util.getServerVal(STR_SHEET_NAME, CELL_SERVER_NAME)
If server = util.STR_EMPTY Then Exit Sub

With Worksheets(STR_SHEET_NAME)
For Each row In Selection.rows
lastRowIndex = row.row
If .Cells(row.row, idColumnIndex).value = STR_EMPTY Then GoTo Continue
If Not util.hasContractData(Worksheets(STR_SHEET_NAME), dataStartRowIndex, row, startOfContractColumns, getContractColumns()) Then GoTo Continue

id = .Cells(row.row, idColumnIndex).value

clearOrderStatusColumns row

util.sendRequest server, STR_CLEARORDER, id

Continue:
Next row

.Cells(lastRowIndex, 1).offset(0, 0).Activate
End With
End Sub
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Hi, I would like to simplify my question above:
The Macro below is triggered for the "active row" or the several rows that are actively marked - but I would like to instead trigger the macro only for the content on row 11 without having to actively mark any row.

So=>
When I click the macro button, I want to trigger the macro based on the content o row 11.
If this is possible, I will then create a 2nd macro based on a clone and change the new macro to instead trigger it based on the content on row 12.

Thanks, and the VBA code is below:

' ========================================================
' place order for active row
' ========================================================
Sub placeOrder()
Dim row As range, server As String, lastRowIndex As Integer

server = util.getServerVal(STR_SHEET_NAME, CELL_SERVER_NAME)
If server = util.STR_EMPTY Then Exit Sub

For Each row In Selection.rows
lastRowIndex = row.row
If Not util.hasContractData(Worksheets(STR_SHEET_NAME), dataStartRowIndex, row, startOfContractColumns, getContractColumns()) Then GoTo Continue
sendPlaceOrder server, row

Continue:
Next row

Worksheets(STR_SHEET_NAME).Cells(lastRowIndex, 1).offset(0, 0).Activate

End Sub
' ========================================================
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,692
Members
448,979
Latest member
DET4492

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top