Detect merged cells in VBA Excel with MergeArea

There are several helpful bits of code for this. Place your cursor in a merged cell and ask these questions in the Immidiate Window: Is the activecell a merged cell? ? Activecell.Mergecells True How many cells are merged? ? Activecell.MergeArea.Cells.Count 2 How many columns are merged? ? Activecell.MergeArea.Columns.Count 2 How many rows are merged? ? … Read more

Show “Open File” Dialog

My comments on Renaud Bompuis’s answer messed up. Actually, you can use late binding, and the reference to the 11.0 object library is not required. The following code will work without any references: Dim f As Object Set f = Application.FileDialog(3) f.AllowMultiSelect = True f.Show MsgBox “file choosen = ” & f.SelectedItems.Count Note that the … Read more

Deleting a file in VBA

1.) Check here. Basically do this: Function FileExists(ByVal FileToTest As String) As Boolean FileExists = (Dir(FileToTest) <> “”) End Function I’ll leave it to you to figure out the various error handling needed but these are among the error handling things I’d be considering: Check for an empty string being passed. Check for a string … Read more

Too few parameters Expected 1, recordset issue

A parameter like [Forms]![SurveyRegister_frm]![SurveyID] doesn’t get evaluated automatically if you open a recordset in VBA. Use this function: Public Sub Eval_Params(QD As DAO.QueryDef) On Error GoTo Eval_Params_Err Dim par As DAO.Parameter For Each par In QD.Parameters ‘ This is the key line: Eval “evaluates” the form field and gets the value par.Value = Eval(par.Name) Next … Read more

how to detect whether VBA excel found something?

Dim rng As Range Set rng = Selection.Find(What:=email, After:=ActiveCell, LookIn:=xlFormulas, _ LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _ False, SearchFormat:=False) If Not rng Is Nothing Then ‘when rng <> nothing means found something’ rng.Activate End IF

Can I make this macro more efficient or faster?

A few tips: Avoid .Select and .Activate as much as possible. Recording macros is a good start to VBA, but the first big step is leaving the “comfort zone” provided by these properties. In the beginning, they’re good, but they’re bound to create problems in the long run. Read up on the following “basic” procedures: … Read more