Macro to Copy and Paste Sequentially - macros

I think this might help answer my question, I am just not savvy enough to understand it. - sorry if my question is redundant.
Macro to copy and paste in next blank cell
I have a dynamic filter that allows me to find data within a data table and display the data in cells A1, B1 and C1
I then have a Macro that will copy data from cells A1, B1, and C1 and paste them to D1, E1, and F1 when I click a button assigned to the macro.
Range("A1:C1").Select
Selection.Copy
Range("D1").Select
ActiveSheet.Paste
What I cannot find or figure out is how to modify the Macro to paste data to D2, E2 and F2 when I change my filter and run the macro/click the button for a second time.
Essentially, I am trying to create a list of data by clicking the button based on what my dynamic filter finds.
I hope this makes sense, and someone can help me.
Thank you!

Found a solution using ElseIf. I am sure it can be done cleaner, but it does what I need it to do. I can now assign the macro to a single button and click it multiple times to form my list.
If Range("G23") = ("") Then
Range("B23:D23").Select
Selection.Copy
Range("G23").Select
ActiveSheet.Paste
ElseIf Range("G24") = ("") Then
Range("B23:D23").Select
Selection.Copy
Range("G24").Select
ActiveSheet.Paste

Related

Notepad++: Record macro will not remember steps taken within Column Editor

I'm trying to remove duplicates in an document. This includes both of entries it finds without moving the order of the entries.
Example
A
B
C
Random info
B
C
Results
A
Random info
I found how to do that via this link and following Method 2. Problem is when recording the macro it doesn't record steps I take when using Column editor. Does anyone know how to fix this or a different method? Thank you
Unfortunatelly, column editor and other plugin actions cannot be recorded because of a bug in notepad++.
However, you can still achieve what you want without using column editor.
Use this macro:
Start macro recording
Control + H to launch "search & replace":
Find what: ^([^\n]*)$\R([\s\S]*?)\R?+^\1$
Replace by: \2
Replace All
Place the cursor at the first position of the file (line 0, character 0) Use the mouse or use Control + G, then 0
Stop macro recording
Now, run your macro with run a macro multiple times and select run until the end of file.
Here is a demo of the process:

{AHK} Defining controls (/Assigning tasks) for those GUI buttons that were creted after script launch

Lets say with some action during running script, you create gui with several buttons via Loop.
Loop, 5
{
Gui, Add, Button,, Number %A_Index%)
}
Gui, Show
How do u then assign actions upon pressing one of buttons?
It seems you cant do it after script launch, and tricks like
ButtonNumber%A_Index%: ;even if i was doing it inside loop.
do something here bla bla
return
do not work.
To do things even worse, i wanted to created these buttons (here for test) from contents of a file, say, each lines text gets utilized to name a button.
you can find similar mini-projects in AHK help files. Buts lets stick with this simple analog.
May be:
Storing and Responding to User Input, third option Variable or g-label is the anwser. Yet it asks for static/global var, but i have troubles declaring these. And g-labels i am not familiar with.
Other option i had in mind is- creating pre-defined buttons (a lot), rename them to my values (from file), and discard rest. hopefully i will be able to use predefined controls.
P.S
AHK help file is a real mess, as a beginner i find it pretty had to fish out complete and meaningful information, instead you have to search and take a bite here and there.
One way is to use a parsing loop and one g-label for all the buttons, then use A_guiControl to get the variable name of the button that called the sub-routine
Example:
; fileread, file_content, Path-to-file
file_content =
(
line with text one
line with text more
line with text other
line with text something
line with text two
)
Loop, parse, File_content, `n, `r
{
Gui, Add, Button, vMyButton%A_index% gButtons, %A_LoopField%
}
Gui, Show
return
Buttons:
msgbox % A_GuiControl
return
GuiClose:
ExitApp
Hope it helps
I have found one possible anwser to my problem. Basicly it involves g-label functionality that blackholyman (lel) suggested.
Using same g-label for all my buttons combined with A_GuiControl comparison inside button control.
Since i have stored buton names in a file, in one line with other data, that is relevant for this button, i can compare each line, by parsing, with button name (A_GuiControl), thats makes me able to retrieve relevant data inside assigned g-label.
May be some one will find it useful. Ill add code later.

How to list out previous command arguments input to minibuffer in Emacs?

Often I need to do replacement with text. I am looking for a way to avoid repeatedly input replacement text.
For example, firstly, I replaced a with b in text;
Secondly, I replaced c with d.
Thirdly, I need to replace a with b again. However, Emacs only store last replacement as default argument.
What is the way to list previous replacement argument, i.e. a to b?
The responses you give to M-% (and other commands that get input from the minibuffer) are kept in the history. Hit the "Up" key to see them.
As the search texts and the replacement texts are kept in the same history, in your case above the history would be a, b, c, d. So, when prompted for the search text, you'd need to hit "Up" four times to come back to a. The history would then change to a, b, c, d, a, so to get back to b as replacement text you'd again need to hit "Up" four times.
You can use M-p instead of "Up" if you prefer.
If you want to see what the previous minibuffer values were without invoking another command you can directly inspect the minibuffer-history variable: C-h v minibuffer-history. This will list all of the values together with the description of this variable.

Natural language processing / commands (prolog)

I want to create a predicate, which recognizes a word (in this case: "save") and starts saving the next words, until the sign/word "end" comes.
It should work like this:
?- save.
one
two
end
true.
The predicate for saving:
save(X) :- assert(listitem(X)).
and then I started like this:
save :- read(save).
read:- X -> save(X).
end --> 'end'.
The problem is, that I can add as much words as I want, but if I want to stop the command with "end", the program fails and actually the words have not been saved.
What part of the predicate is wrong? I'd be very happy for some help.
Thank you in advance!
This is some extremely confused code. Here's what you wanted:
:- dynamic listitem/1.
readline(Line) :-
% this is an SWI extension, but it's very handy
read_line_to_codes(user, Codes),
atom_codes(Line, Codes).
save :-
readline(X),
(X \= end -> (assertz(listitem(X)), save)
; true).
Odds are good, somewhere in the code you didn't bring, all you were missing was the effect of the ; true there: that when you find end, you're finished, but not that you failed. But you have a lot of problems here.
save/0 calls read/1, which is a system predicate. All this is going to do is read a word from the user (ending with a period!) and notice that it isn't the word "save". Unfortunately, reading a whole line without periods at the end is a somewhat non-trivial task in Prolog, hence the pile of code in my solution.
read/0 is not called by anything.
The syntax X -> save(X) is almost certainly not what you want. This is the first occurrence of X in the predicate, and so it probably isn't doing you much good to test it conditionally before it has a value.
end --> 'end'. is a DCG rule, but you aren't using phrase/2 anywhere to invoke it (nor are you using end/2 directly with a difference list).
assert/1 is a really bad habit to get into. The ISO predicates asserta/1 and assertz/1 are not only portable, they also give the reader a better idea what the effect on the fact database will be.
Similarly, you have no dynamic declaration for listitem/1, which would raise portability and improve readability.
I would use a 'state machine' approach: it's so simple!
:- dynamic listitem/1.
loop(Mode) :- read(W), loop(Mode, W).
loop(_, stop).
loop(skip, save) :- loop(save).
loop(skip, _) :- loop(skip).
loop(save, W) :- assertz(listitem(W)), loop(save).
test:
1 ?- loop(skip).
|: asd.
|: save.
|: ok.
|: ok1.
|: stop.
true
.
2 ?- listing(listitem).
:- dynamic stackoverflow:listitem/1.
stackoverflow:listitem(ok).
stackoverflow:listitem(ok1).
true.

emacs + vimpulse-visual-mode + "linewise" text selection

Is it possible to make visual-line-mode (one after pressing V from normal mode) conduct as if first mark was in the beginning of the first line of selection and second mark - end of the last line?
For an example, currently after V, j and M-x comment-dwim:
here<cursor>is a
simple example
becomes
here;; is a
;; simp
le example
whereas desired result is often:
;; here is a
;; simple example
Of course, one can write a wrapper for comment-dwim, but I suspect/hope that there is a more correct solution.
Thank you in advance.
Doesn't V (vimpulse-visual-toggle-line) already do that?
Linewise selection will select whole lines. (I use this all the time)
The behaviour you're talking about will occur if you're using v (vimpulse-visual-toggle-char).
comment-dwim calls comment-or-uncomment-region to perform the actual commenting on the marked region. There is no option to extend the region to beginning of the first line and/or end of the last line. You will have to write a wrapper or advice comment-or-uncomment-region to achieve the effect you want.