I have an excel concatenate formula that I need to paste into another program. I have successfully entered the tab keystroke with CHAR(9), but I can't seem to get the down arrow keystroke to work. I have tried using CHAR(40), but the program I am pasting to does not recognize this.
Here is my formula:
=CONCATENATE(M16,CHAR(9),CHAR(9),CHAR(9),CHAR(9),CHAR(9),M17,CHAR(9),CHAR(9),
CHAR(9),CHAR(9),CHAR(9),LEFT(M9,55),CHAR(9),CHAR(9),CHAR(9),CHAR(9),CHAR(9),
RIGHT(M9,100),CHAR(9),CHAR(9),CHAR(9),CHAR(9),CHAR(9),"=",M18,CHAR(9))
I want to replace the 5x CHAR(9), which is 5x the tab key, with just one text entry for down arrow.
Does anyone know another way of doing this other than CHAR(40)?
I'm not entirely clear about what you're after, so I'll try to cover both bases:
If you want the text to start on t new line then:
char(13) will give you a carriage return
char(10) will give you a line feed
If you are (literally) sending these keystrokes to another application then you may also want to investigate the Application.SendKeys method which sends keystrokes to the active application. You can do things like:
Sub MySub()
AppActivate ("Notepad")
SendKeys ("Some text{TAB}{DOWN}{TAB}Some more text")
End Sub
Related
Very rudimentary: I wish to press F1 (Windows OS) to print, i.e., "XZ" in the active Excel cell (as plain/unformatted text), but in such a way that I can then enter "123" immediately thereafter, hence resulting in a cell value of XZ123.
This .xls is shared by other users, four of whom are in the document adding data at any given time. We save this to a Sharepoint folder, but nobody on the team ever accesses the document via the web version of Excel. We instead just double-click the document, at which point Excel boots up from our local hard drive, but when the document loads, we can see other users' active cell(s) based on highlights around the cells with their initials.
My hope is that this silly two-letter automation can be triggered only from my computer, and not embedded in the document file itself.
Huge thanks in advance for any guidance! This seems crazy simple but I honestly can't figure out how to do it. Cheers!
Unfortunately the only way for vba to enter edit mode is to use SendKeys
You'll need to use OnKey to map the function to F1
Const StringToEnter As String = "XZ"
Sub EnterValue()
Application.SendKeys "{F2}" & StringToEnter
End Sub
' Run this once to map F1 key. Maybe call from the `Workbook_Open` event
Sub SetupMappingToF1()
Application.OnKey "{F1}", "EnterValue"
End Sub
I am trying to replace Enter key with Alt+Enter so that I can write multiline in cells with ease.
I have seen that there is a function Application.OnKey and Application.SendKeys and I wanted to use those something like this:
Application.OnKey "~" , Application.SendKeys("%~")
But where do I place those? Or any other ideas?
I think I agree with #Andreas, this is unlikely to work using these methods.
This is what I tried: I made a button Button1 and in its click method I assign the Enter key to send Alt-Enter as you suggest in the question:
Sub Button1_onClick()
Call Application.OnKey("~", "SendAltEnter")
End Sub
Sub SendAltEnter()
Application.SendKeys ("%~")
End Sub
This does in fact re-route the Enter key, but apparently the Alt-Enter results in another call to the method for the "Enter" part of "Alt-Enter" -- it results in an infinite loop the first time you hit enter after having clicked the button, and you have to restart your Excel application to clean it up.
I also tried this, simply using another key near Enter, namely # (at least on German keyboards) which you could hit instead of Alt-Enter:
Sub Button1_onClick()
Call Application.OnKey("#", "SendAltEnter")
End Sub
Sub SendAltEnter()
Application.SendKeys ("%~")
End Sub
The key '#' is intercepted, but not if you are in input mode in a cell, only if the focus is somewhere in the worksheet.
I think you'll have to do this outside of Excel using a keyboard remapping tool for Windows. I quickly found https://www.howtogeek.com/710290/how-to-remap-any-key-or-shortcut-on-windows-10/ by googling but know nothing about it or if it is legit or not.
Have you considered just using Shift + Enter to insert a carriage return instead?
I have a long chunk of code that handles date data from a hidden datasheet, however anytime I enter a new date trough a userform, it writes it into the cell in the database in a format that for some reason can't be handled error free by my code chunk.
The problem is I need a sub to change the format (which is easy) but it does not actually apply the formatting unless I manually go into the datasheet, enter the cell and press enter.
I have searched and could not find a solution on how to do this in VBA, obviously this code is supposed to run automatic flawlessly plenty of times and having to manually go in an enter the cell defeats the entire purpose of the programming.
Sub Testing123()
MsgBox "run"
Workbooks("Excel Stock System.xlsm").Worksheets("DataNews_Events").Columns(8).NumberFormat = "dd.mm.yyyy hh:mm"
'something magic that actually automatically applies the format
End Sub
I have a spreadsheet with hundreds of cells containing formulas like =('Pricing Master'!$E135*'Pricing Master'!$L$29). I would like to batch add the ROUNDUP formula, so that they all read, for example, =ROUNDUP('Pricing Master'!$E135*'Pricing Master'!$L$29,0). A simple Replace All will not work, as it requires both the function call preceding as well as the Number argument following. Not providing both at the same time produces an error. This creates an issue with batch editing using Replace All.
I am sure that there is a way to do this with the Paste Special function, although if there is another way I would be glad to hear it.
My approach is this and I do this often with large sheets with many formulae:
One : select the row(s) or column(s) you want to work with,
Then edit/replace “=(“ with “xyxy(” (I use xyxy as it just doesn’t come up...
Now all replace operations will be quicker as there is no re-calc happening...
So now do edit/replace “xyxy” with “xyxyroundup(“ and “)” with “,0)”
Then just replace “xyxy” with “=“
And wait for it to finish its calculations...
loop through each cell and add formula to the original formula. Like this
Sub updateFor()
Dim r As Range
For Each r In Selection.SpecialCells(xlCellTypeFormulas)''only cells with formula in
r.Formula = "=ROUNDUP(" & Mid(r.Formula, 2) & ",0)"
Next r
End Sub
just replace the selection with the range you want to edit
if you arnt familiar with vba heres a quick guide
press ALT + F11 to show the vba editor
from insert menu select module
module1 should appear in the project window in the top left,
click on this
a large window should open on the right paste the above code in
go back to your worksheet and select the cells you want to roundup
goto to the view ribbon click the macro button on the far right
select the macro 'updateFor' and press run
How can you add an apostrophe in every field in an Excel spreadsheet without individually typing it in? I have got like 5k fields
I'm going to suggest the non-obvious. There is a fantastic (and often under-used) tool called the Immediate Window in Visual Basic Editor. Basically, you can write out commands in VBA and execute them on the spot, sort of like command prompt. It's perfect for cases like this.
Press ALT+F11 to open VBE, then Control+G to open the Immediate Window.
Type the following and hit enter:
for each v in range("K2:K5000") : v.value = "'" & v.value : next
And boom! You are all done. No need to create a macro, declare variables, no need to drag and copy, etc. Close the window and get back to work. The only downfall is to undo it, you need to do it via code since VBA will destroy your undo stack (but that's simple).
The way I'd do this is:
In Cell L2, enter the formula ="'"&K2
Use the fill handle or Ctrl+D to fill it down to the length of Column K's values.
Select the whole of Column L's values and copy them to the clipboard
Select the same range in Column K, right-click to select 'Paste Special' and choose 'Values'
i use concantenate. works for me.
fill j2-j14 with '(appostrophe)
enter L2 with formula =concantenate(j2,k2)
copy L2 to L3-L14
More universal can be:
for each v Selection : v.value = "'" & v.value : next
and selecting range of cells before execution