Showing posts with label VBA. Show all posts
Showing posts with label VBA. Show all posts

Wednesday, March 19, 2014

VBA Excel - How to Insert Column

This is example of how to insert column in an excel via VBA script:

ws.Columns("S").Insert

Excel VBA - How To Insert Rows

Inserting a Row at at Row 2
Range("A2").EntireRow.Insert

'Inserting 3 Rows from 3
Rows("3:5").EntireRow.Insert

Inserting from row 1
ws.Rows(1).Insert shift:=xlShiftDown

Tuesday, March 18, 2014

Excel VBA – How to copy entire row

Sheets("Sheet1").Range("A1").EntireRow.Copy Destination:= Sheets("Sheet2").Range("A1")

 If you wish to copy the entire row to the next available row on Sheet2:
  Sheets("Sheet1").Range("A1").EntireRow.Copy Destination:= Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1)

 This assumes that you already are capable of creating a macro/event handler in the VBE and simply need the syntax to copy the row.

Excel VBA – How to Find if an Array Contains a String

Function IsInArray(stringToBeFound As String, arr As Variant) As Boolean IsInArray = (UBound(Filter(arr, stringToBeFound)) > -1) End Function