I'm looking for completely empty comments to delete in VBA. However, the comments are never truly empty since there's always the name of the author (even if he/she put nothing in the comment). I tried various methods, and my approach is to slice the string right after the ":" that goes after the author's name to see if it contains any symbol other than "", the problem is that when you enter a new line in a comment, Excel does not regconize that as a "" to check agaisnt. I have tried to check against vbNewLine but that does not work. Any suggestion would be greatly welcomed.
do a replace: replace(replace(range(xxx).Comment.Text),chr(13),""),chr(10),"") to remove the newlines
Related
Please help me with the code to insert a column in excel using vba. Here is what I am doing -
Sheet1.Range("A:A").EntireColumn.insert
That code works fine for me.
Sheet1.Range("A:A").Insert works also. Range("A:A") is already referencing an EntireColumn.
There are a few things to check if it's not working for you:
You're referencing an object called Sheet1. Is that definitely the codename of the worksheet you want to change? Make sure you understand the difference between sheet name and codename. You could try referencing it by the sheet's name instead: Worksheets("Tabname").Range("A:A")...
Is the worksheet protected? That would give you an error if it is.
Is there any data in the right-most column of the spreadsheet? That would also cause an error as Excel doesn't know what to do with it. If you're not 100% sure, select the entire right-most column of the sheet and hit delete to remove anything that might cause an issue.
Lastly, can you insert a column manually? i.e. select left most column, [right-click] and [Insert]?
I think you got the Sheets property wrong, this works for me :
Sheets(1).Range("A:A").EntireColumn.Insert
You should clearly mention what you are trying to do; what type of problem you are facing.
However, you should try out the below code. hope this will help
Sheet1.Range("A:A").EntireColumn.Insert Shift:=xlToRight
while inserting a new row or column make sure to refer to the entire row or column. Check if there are any marge cells at the right of column A. That can possibly be causing the problem.
Sub TryMe()
Columns(1).Insert
End Sub
Also, this is a very generic question. If you can Google something and figure it out in a fraction of the time that it takes to craft a question and post it on SO, just Google it. If your question is very unique, and after hitting multiple dead ends using Google, then ask the SO community. I found the 3 links below using a Google search that took around 1 second.
https://www.automateexcel.com/vba/insert-row-column/
https://excelchamps.com/vba/insert-column/
https://www.educba.com/vba-insert-column/
The situation:
I am working on an Excel file that offers some worksheets to calculate different things. The last of these worksheets is a summary of all the others that is preformatted for perfect printing on a standard paper sheet. I want to print this summary by clicking a button on the main page (first worksheet). The code behind this button is stored in "Table1" and looks like this:
Sub Print()
Worksheets("Table5").PageSetup.PrintArea = "B2:N48"
Worksheets("Table5").PrintPreview
End Sub
The problem:
I've got a german Keyboard with "," as decimal separator on the NumPad. My whole system uses the "," as this. After opening the file, I can just enter something like "1,4" in a cell of choice and everything works. My problem starts when printing the summary via VBA code (see above). After this, pressing my NumPad's "," results in getting a "." instead. The standard "," of the keyboard still works as supposed.
If I accidentially use the NumPad after printing, type "1.4" in a cell and hit Enter, the cell gets a user defined format as date (01.04. or in your case propably 01/04 or something else) and crashes everything.
What I tried:
I made a simple test file with only the two code lines above and just a blank space to print. I found out, that the problem only appears, if I really print the summary. Starting the preview and then cancelling it before printing does not cause the problem.
I checked the file with Excel 2010 and 2016 and the problem appeared in both cases.
If I save the file, close it and open it again, the problem is gone, but new formatted cells will stay and crash the file.
What I also tried is checking Excel's options before and after printing, but nothing changed.
My guess:
There might be a problem with Excel-VBA's "PrintPreview" in general. It would be nice to get a confirmation of my problem, a solution for it or a workaround. I cannot change the printing process to standard printing, because my real file is much more difficult.
Best wishes
RaspiManu
I was able to recreate the problem. The odd thing is that under File > Options > Advanced the decimal seperator symbol will still show as the comma. However the problem gets fixed with:
Application.DecimalSeparator = ","
Which would set the decimal seperator to the comma again.
Edit, I guess it's a known bug as I found this question on the same issue here. A solution provided there would be instead of Worksheets("Table5").PrintPreview use:
Application.CommandBars.ExecuteMso "FilePrintPreview"
However for this option to work, the activesheet needs to be the one you want to print from. So I would still prefer to use the first suggestion and set the DecimalSeperator.
Could someone please tell me what's wrong with this formula ?
=CONCATENATE(=LEFT(CELL("filename",A1),FIND("[",CELL("filename",A1))-1),"GroupFolder\fileName.png")
Why doesn't the concatenation formula accept the first argument to be an input even though it returns a string?
I'm trying to get the path of a certain file inside the directory of the excel document.
I see no problem with this except a minor typo. Just remove the = sign before the LEFT function. In addition, please take note that CELL function will return nothing if your worksheet is unsaved. So, save your worksheet first.
=CONCATENATE(LEFT(CELL("filename",A1),FIND("[",CELL("filename",A1))-1),"GroupFolder\fileName.png")
Hope this helps..
I am trying to use one of the excel hidden field for the purpose of referencing. Basically column(A:A) is hidden and it contains specific IDs that I can use it to reference it to another sheet.
I could have moved the column (A:A) further away so that the user does not see it, but my issue is that I have written too many lines of code already. I guess it is poorly constructed, because if I were to move any of my columns, my entire program would definitely break. I could try to fix it, but that would mean I would have to over analyze my own code and I either wouldn't understand it or wouldn't find my mistake.
So, anyways, I have a Range.Find function, which is looking in the hidden field, but returns nothing. I could try to unhide it, and hide it again, but I want to know that if there is a solution in Excel, then to not ignore the hidden field.
Set myCell = Columns(1).Find("search_string", lookat:=xlWhole, LookIn:=xlFormulas)
Debug.Print myCell.Row
Replace "search_string" to the ID you are looking for.
I'm using a small macro to add and delete rows in a protected worksheet. For this each line has a "Delete" button. When a new line is added, the last existing line is copied (including the "Delete" button) and then its content is cleared.
For deleting the rows I hand over some parameters including the "Delete" button's (and thus the item's) row. For this I use:
RowToDelete = ActiveSheet.Shapes(Application.Caller).TopLeftCell.Row
This code works fine for existing lines, but it will fail for all lines added since the workbook was last opened (except for the last one). For all other it will delete the next line that was added instead of the "real" one.
I guess that this is a cache problem, as the "Application.Caller" contains the right string, but returns the row of the copied shape that no longer carries that name.
Is there a way to clear the relevant cache or to force Shapes() to not use the cache?
Thanks a lot for your help.
I've found a workaround that I'm not too happy with but has to do the trick for now. I'm using random shapenames to avoid the wrong return values. It seems that if the shape name did not exist before the lookup works.
shp.Name = "Shape" & Format(i, "0000") & (Rnd * 999)
Must be some cache problem, as the button work fine after saving and reopening the workbook.
I had the same problem. The buttons were created by other buttons like yours. However, it only started doing it when in the code that creates the buttons, I started adding a name to it. So another not so satisfying way of dealing with it is to just not have the "shp.name= " line. When I took that out it stopped doing it. My guess is that in the natural way of naming buttons it naturally avoids that. Just like when you have a sheet, delete it, and add another sheet, it still remembers the old sheet and names the new sheet a higher number.
A code to delete the cache would be nice. I am sure somebody knows how to do that if the question was asked differently. Searching for that gives:
Application.Restart()
I haven't tried it though.