IF statement: how to leave cell blank if condition is false (“” does not work)

Unfortunately, there is no formula way to result in a truly blank cell, “” is the best formulas can offer. I dislike ISBLANK because it will not see cells that only have “” as blanks. Instead I prefer COUNTBLANK, which will count “” as blank, so basically =COUNTBLANK(C1)>0 means that C1 is blank or has … Read more

Test or check if sheet exists

Some folk dislike this approach because of an “inappropriate” use of error handling, but I think it’s considered acceptable in VBA… An alternative approach is to loop though all the sheets until you find a match. Function WorksheetExists(shtName As String, Optional wb As Workbook) As Boolean Dim sht As Worksheet If wb Is Nothing Then … Read more

How do I put double quotes in a string in vba?

I find the easiest way is to double up on the quotes to handle a quote. Worksheets(“Sheet1”).Range(“A1”).Formula = “IF(Sheet1!A1=0,””””,Sheet1!A1)” Some people like to use CHR(34)*: Worksheets(“Sheet1”).Range(“A1”).Formula = “IF(Sheet1!A1=0,” & CHR(34) & CHR(34) & “,Sheet1!A1)” *Note: CHAR() is used as an Excel cell formula, e.g. writing “=CHAR(34)” in a cell, but for VBA code you use … Read more

How can I send an HTTP POST request to a server from Excel using VBA?

Set objHTTP = CreateObject(“MSXML2.ServerXMLHTTP”) URL = “http://www.somedomain.com” objHTTP.Open “POST”, URL, False objHTTP.setRequestHeader “User-Agent”, “Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)” objHTTP.send “” Alternatively, for greater control over the HTTP request you can use WinHttp.WinHttpRequest.5.1 in place of MSXML2.ServerXMLHTTP.