Column C has dates in mm/dd/yy ss-mm-hh format. I want to remove the ss-mm-dd from each cell of that column. How can I do that using openpyxl.
Sorry I do not have any script to present at this time since I have no clue where to start.
This should do what you want:
import openpyxl
for row in ws.iter_rows(min_col=3, max_col=3):
for cell in row:
cell.value = cell.value.split()[0]
Related
Can someone please tell me what does this line do:
ActiveSheet.Range("AH1").FormulaArray = "=iferror(MATCH(1,(plan!T3:T20000=AF1)*
(plan!W3:W20000=MONTH(E1)),0),0)+2"
plan is a name of sheet in my Excel file. thanks in advance.
The formula is a doing a multi-criteria CountIF. Without seeing the data, it is doing the following.
Count the data in column T if any of the rows match what is in cell AF1, but only count it if the corresponding month shown in Column W matches the Month shown in cell E1. Then add 2.
this add array formula (usually inserted with Ctrl+Shift+Enter) to the cell AH1. It seems that formula checks if value in column T in plan sheet is equal to this one in AF column and month of date in E column equals to value in plan!W column, plus 2 for some reason.
so I have ABCDE columns and I want to see rows of the cells that are not empty in the C as well as D column. how do I do this? I know I can have one column do that but that way it would exclude the information in the other column.
Let me know if this doesnt make sense. I'll try to explain with an example
I am a little confused by your question as to whether you are trying to use Conditional Formatting or to create a filter.
If you are trying to use Conditional Formatting:
It sounds like you are trying to highlight a row if there is not a blank cell in column C and not a blank cell in column D of that row.
Create a Conditional Formatting rule with the following:
Apply to Range A1:E1000 <-- (or however many rows of data you have)
Format cells if... SELECT "Custom formula is"
=or(NOT(isblank($C1)),NOT(isblank($D1)))
Formatting style Pick a color to highlight the row
This rule will highlight columns A-E for each row that has data in both column C and column D.
Is it possible to import data from a column in an different file with the same date in the column.
On one sheet i have 7 dates created in different columns with
15-09-15 16-09-15 17-09-15 18-09-15 19-09-15 20-09-15 21-09-15
O
M
N
Now will i show data from cells from a column from a different file with the same date as a cell in the kolom where will be paste the data.
I have found the solution with a formule and not with a macro.
With using the formule HLOOKUP() i have the right result.
I have a problem with VBA code. I have a sheet with a lot of data around the cells I want. I need to select data in column F, but the position of the first and last cells between the range is to be selected is changing up and down. I created the non empty cells in row X where there is no data do the LastRow function has any refernece but now I dont know how to select the first row
thx for help
If F1 is empty, this selects the first cell with data in the F column
Worksheets("Sheet1").Range("F1").End(xlDown).Select
If F1 may be non-empty you can add a check to see whether it contains text.
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"