ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Run a macro only for the selected fields(records) (https://www.excelbanter.com/excel-programming/419406-run-macro-only-selected-fields-records.html)

[email protected]

Run a macro only for the selected fields(records)
 
Hoi,

At this moment I have a macro which run an action for all the records
within the sheet.
The macro looks in column A and if filled in with a value "y" it runs
the action for the first row and when finished it goes to the next
record till the last one in the sheet. For info: This macro copies
date of the activ record to a sheet and then print it out.
I want to change this macro on such a way that it runs not from the
first record till the last of the sheet, but only for each record that
is activated (=selected). This could be a range or with ctrl-x
selected different ones.

The macro should something like.......
for all selected fields, run the macro for each selected record and if
in column A of this activated record is a "y" registered run another
actionmacro.

Somebody can help me ?

regards,
Johan

Don Guillett

Run a macro only for the selected fields(records)
 
As always, post your macro for comments.

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

wrote in message
...
Hoi,

At this moment I have a macro which run an action for all the records
within the sheet.
The macro looks in column A and if filled in with a value "y" it runs
the action for the first row and when finished it goes to the next
record till the last one in the sheet. For info: This macro copies
date of the activ record to a sheet and then print it out.
I want to change this macro on such a way that it runs not from the
first record till the last of the sheet, but only for each record that
is activated (=selected). This could be a range or with ctrl-x
selected different ones.

The macro should something like.......
for all selected fields, run the macro for each selected record and if
in column A of this activated record is a "y" registered run another
actionmacro.

Somebody can help me ?

regards,
Johan



[email protected]

Run a macro only for the selected fields(records)
 
Herewith my macro.
It's selecting now each record from the last row till the second
(based on letter "y" in column A).
The loop should run only within the records of the selected field
(which could be a range next to eachother or some fields selected with
the CTRL button on) and in the selected records look for the letter
"y" in column A and based on that do the actions.

Sub
LastRow = Cells.Find("*", [A1], , , xlByRows, xlPrevious).Row
lr = LastRow
lr1 = lr + 1
co = 1
For li = lr1 To 2 Step -1
If InStr(Cells(li, co), "y") = 1 Then
Cells(li, co).Select
acr = ActiveCell.Row
Range("B" & acr).Select
act = ActiveCell.Text
'on this point the macro does some copy-paste actions to another sheet
End If
Next li
End Sub


help me out please.

regards,
Johan


All times are GMT +1. The time now is 12:13 PM.

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