Posts

Showing posts from January, 2015

Use of variables

Sub VBAClassVariableEX() 'VBA macro Code to understand the function of Variables Workbooks.Add ActiveSheet.Name = "VBAClassVariableEx" Dim i As Integer Cells(1, 1).Value = "Sr.No" For i = 2 To 12 Cells(i, 1).Value = i - 1 Next Cells(1, 2).Value = "Particular" Cells(2, 2).Value = "First Name" Cells(3, 2).Value = "Last Name" Cells(4, 2).Value = "Date of Birth" Cells(5, 2).Value = "Birth Day, Month" Cells(6, 2).Value = "Birth Year" Cells(7, 2).Value = "Years" Cells(8, 2).Value = "Months" Cells(9, 2).Value = "Days" Cells(10, 2).Value = "Hours" Cells(11, 2).Value = "Minute" Cells(12, 2).Value = "Seconds" Cells(1, 3).Value = "Details" Dim username As String Dim firstname As String Dim lastname As String Dim yearpassed As Single Dim monthpassed As Single Dim daypassed As Single Dim hourpassed As Single Dim ...

Use of Strings

Private Sub VBAStringFunctionExample() 'VBA macro Code program for understand the function of string 'Note: Enter on Sheet1 Column B3 (Raw No 3 nd Column no 2) 'first Name 'Length of first Name 'Last Name 'Length of Last Name 'All UpperCase 'All lowercase 'Concatenation 'Code start Dim Username As String Dim Firstname As String Dim Lastname As String Dim Strlen As Integer Dim spaceloc As Integer Username = InputBox("Enter your First and Last name.", "Username") spaceloc = InStr(1, Username, " ") Firstname = Left(Username, spaceloc - 1) Sheets("Sheet1").Activate Cells(3, "C").Value = Firstname Strlen = Len(Firstname) Cells(4, "C").Value = Strlen Strlen = Len(Username) Lastname = Mid(Username, spaceloc + 1, Strlen - spaceloc) Cells(5, "C").Value = Lastname Strlen = Len(Lastname) Cells(6, "C").Value = Strlen Cells(7, "C").Valu...

Copy diff workbook data in one

Sub Copy_different_file_data_in_one_file() 'VBA Macro Code to Copy Different workbook data in one workbook and compile it MkDir "D:\Study\Excel and VBA Practice\Macro18Jan" MkDir "D:\Study\Excel and VBA Practice\Macro18Jan\VBAClass" Workbooks.Add ActiveWorkbook.SaveAs "D:\Study\Excel and VBA Practice\Macro18Jan\VBAClass\Jan.xlsx" Workbooks.Add ActiveWorkbook.SaveAs "D:\Study\Excel and VBA Practice\Macro18Jan\VBAClass\Feb.xlsx" Workbooks.Add ActiveWorkbook.SaveAs "D:\Study\Excel and VBA Practice\Macro18Jan\VBAClass\Mar.xlsx" Workbooks.Add ActiveWorkbook.SaveAs "D:\Study\Excel and VBA Practice\Macro18Jan\VBAClass\Working.xlsx" Workbooks("Jan.xlsx").Sheets("Sheet1").Activate Range("A1").CurrentRegion.Copy Workbooks("working.xlsx").Sheets("Sheet1").Activate Range("A1").PasteSpecial xlPasteValues Application.CutCopyMode = False ActiveSheet.Name...

Copy one column data to another

Sub Macro2copy_one_column_data2another() 'VBA Macro Code to copy one column to another Sheets("Sheet1").Activate Range("A:A").Select Selection.ClearContents Range("C:C").Select Selection.ClearContents Range("B:B").Select Selection.Cut Destination:=Range("A:A") Range("D:D").Select Selection.Cut Destination:=Range("C:C") Range("C:C").Select End Sub