VB.NET Code to Change Excel 2007 Column Cell Format to Number no Decimal - vb.net

VB.NET code to change Excel 2007 Column Cell Format from Text to a Number no Decimal.
Right now Column F shows values that look like
3E+13
3E+13
Manually changing it to a Number with No Decimal shows the correct value.
30000046605562
30000041582875
Of course I would like to automate this.

Select the rows (maybe programmatically) and perform
Selection.NumberFormat = "0"
To select all cells in the sheet call
Cells.Select

Related

VBA: Highlight a row with a specific column value

I am working on a very large excel 2010 workbook with several sheets.
One of the sheets is called "RatePlan" and one of the columns in this sheet is "RatePlanCde".
Some of these "RatePlanCde" (a total of 2514) are not valid anymore and have been highlighted in Red.
I need to find if "RatePlanCde" column exists in any other sheets. If so, then highlight the row with the invalid "RatePlanCde" value in all the sheets in Red too.
Can this be done using a VBA script and how?
Formula for conditional formatting is a simple VLookup
The following formula assumes that the codes in the "other" sheets is in Col A, the codes are in the Rateplan-Sheet in Col C and the "INVALID"-marker in COl D:
=VLOOKUP(A2;RatePlan!$C$2:$D2515;2;FALSE)="INVALID"

MS Excel Formula - Determine count for specific text across multiple columns

I am trying to write a formula in MS Excel that will let me know if the text "Yes" is found in any of three selected columns. Below is the formula I created but it does not seem to be working. When I drag the formula to the other rows I get a "Yes" value for rows that do not have the text "Yes". The values in the columns I am searching are blank or have "Yes" text.
=IF(COUNTIF(AF3:AF2378,"Yes") + COUNTIF(AG3:AG2378,"Yes")
+ COUNTIF(AI3:AI2378,"Yes")=0, "1","Yes")
Use:
Application.WorksheetFunction.Match("Yes", Array1, Array2, Array3)
From your question it seems that you want to check for each row alone. To do this you need to enter the formula for each row and fill down For example, at cell AJ3, you can write:
=IF(OR(AF3="Yes", AG3="Yes", AI3="Yes"), "Yes", "1")
Enter this formula at AJ3 (or any other column at row 3) then copy/paste on all the column.

VBA Drag down Vlookup

All,
I have a data sheet of around 1.000 values which need a matching amount (the amount of valueschanges every day) . These amounts can be found in another tab "Data".
so using a Vlookup code in VBA should help me. The code I'm using is:
Sheets("Data").Range("E2") = Application.WorksheetFunction.VLookup(Sheets("Data").Range("D2"), Sheets("Blocked").Range("C:D"), 2, False)
Result should appear in column E responding with the row of the lookup_value which can be found in column D.The table and column index don't change being Sheets("Blocked").Range("C:D")and 2
This code gives me the result I wanted but as I tried to drag down the formula with this function:
Range("E2").AutoFill Destination:=Range("E2:E440")
How can I drag down this formula without needing to create a seperate vlookup for each row?
You should use the Formula as an R1C1 reference and then u will be able to drag down
Sheets("Data").Range("E2").FormulaR1C1 = "=VLookup('Data'!R[-1]C,'Blocked'!C[-2]:C[-1],2,0)"

VBA Excel Date Generator

I was wondering if there is a way using vba or excel to make an array of each day starting with Oct. 10th 2010 and ending with Sept. 30 2015. Unfortunately the dates have to be in the format YYYYMMDD, such as 20091001 and 20150930.
Thanks for the help
For a non-VBA solution KingsInnerSoul's solution is very good.
For VBA, you could do something like this:
Sub tgr()
Dim arrDates() As Variant
Dim dtStart As Date
Dim dtEnd As Date
'Assign start and end dates
dtStart = CDate("Oct 10, 2010")
dtEnd = CDate("Sep 30, 2015")
'Create the array by evaluating an Index formula
arrDates = Application.Transpose(Evaluate("INDEX(TEXT(""" & dtStart & """+ROW(1:" & dtEnd - dtStart + 1 & ")-1,""YYYYMMDD""),)"))
'Example of how to access the array values
MsgBox arrDates(1) & Chr(10) & _
arrDates(2) & Chr(10) & _
arrDates(3)
'You could iterate over the array with a loop also,
'or use any other array function, like Filter(), etc
End Sub
Create a list in Excel:
If you go to excel,
In the first top cell type 10/10/2010
Then right click on the cell - and select Format Cells,
Then go to the Custom category
In the Type input area type yyyymmdd - verify that it is the right format in the Sample field (I had it set to yyyymmdd;# )
Press OK
Once the cell is highlighted, you can see a border around it, and a + in the lower right corner of the cell.
Click on the + and drag it down as many rows as you need to - it will copy the cell's content and create a series with each cell adding a day.
Create a single row list in Word:
Once you created that single column in Excel, in the column next to it, type , (comma), and drag it down the same way in order to copy it next to the whole series.
Copy both columns in Excel.
Paste it to MS Word.
In the lower right corner an icon will appear - Paste Options.
Click on the Paste Options icon and select 'Keep Text Only' - It is the 'A' icon. Now you will have a single text column with the number, a tab character, comma, and Enter character.
Open the Search and Replace by pressing CTRL+H.
In the 'Find What' input field type ^p - it is the code for Enter.
Leave the `Replace With' field empty.
Press on `Replace All'.
Confirm the number of total replacements popup window by pressing OK.
To get rid of the Tab character, repeat steps 6-10 but search and replace ^w.
More information about special characters.
Related questions:
VBA convert range to array and format date
excel vba filling array
VBA Excel - Problems with a simple macro to auto-fill cells for a budgeting spreadsheet I'm attempting to make
Fill two columns with random dates
How to force Excel to automatically fill prior year in column instead of current year?
Fill dates array and add dummy variables
https://stackoverflow.com/questions/25277464/fill-dates-gap-in-excel
For the sake of an image, add October 10, 2010 (formatted yyyymmdd) in say A1 and HOME > Editing, - Fill:, Series...
for a column (or change Series in selection for in a row).

How to convert multiple column from text to date?

In my excel file, there are hundred columns. I want to convert some columns (eg. Column A, C,F, G..) from text to date. It really take time if manually change each column one column by one.
How can I do it ? By using VBA ?
The original text column format just like '31-Dec-2011 00:00:00'. I want to convert to 'dd/mm/yyyy' 31/12/2011
Thanks
If you actually want to chop the time off in each of the cells then this might be an approach:
If the target times are in column A of a sheet called "target" and the column header in A1 is "StartTime"
You could amend the below and add an argument so that it takes the column address. Then it could be called several times to carry out this operation on several columns.
Sub ChopOffTime()
dim mySheetName as string
mysheetname = "target" '<<<<change to your sheet name
myLstRow = Excel.ActiveWorkbook.Sheets(mysheetname ).Cells(Excel.ActiveWorkbook.Sheets(mysheetname ).Rows.Count, Excel.ActiveWorkbook.Sheets(mysheetname).Range("A2").Column).End(Excel.xlUp).Row
With Excel.ActiveWorkbook.Sheets(mysheetname)
.Columns("B:B").Insert Excel.xlToRight
.Range("B2:B" & myLstRow).FormulaR1C1 = "=TIME(HOUR(RC[-1]),MINUTE(RC[-1]), SECOND(RC[-1]))"
.Range("B1") = "StartTime" '<<<<<change to appropriate header
.Columns("B:B").Copy
.Columns("A:A").PasteSpecial Excel.xlPasteValues
.Columns("B:B").Delete Excel.xlToLeft
End With
End Sub
Thanks all.
To simplified the procedure, I just developed some macro for user to run to change the column format, and then they can import the excel the mdb without error.
Use the following for the columns in question:
Columns("A:A").Select
Selection.NumberFormat = "m/d/yyyy"