Excel find smaller values than x > identify date/time and paste it
up vote
-1
down vote
favorite
I am having data (image below) and task is to find values <3, identify what date and hour is and paste dates, hours in another spreadsheet of that cells. Does any have ideas?
Option Explicit
>
> Sub CopyPaste()
>
> Dim LastRow As Long, LastCol As Long, Row As Long, Column As Long, x
> As Long Dim wb As Workbook Dim ws As Worksheet, ws2 As Worksheet Dim
> SearchRange As Range, Cell As Range
>
> Set wb = ThisWorkbook Set ws = wb.Sheets("DataHorizontal") 'the sheet
> in which your data is Set ws2 = wb.Sheets("Overview") 'the sheet where
> you want your result
>
> LastRow = ws.Cells(Rows.Count, 1).End(xlUp).Row LastCol = ws.Cells(1,
> Columns.Count).End(xlToLeft).Column
>
> Set SearchRange = ws.Range(ws.Cells(2, 2), ws.Cells(LastRow, LastCol))
>
> x = 27
>
> For Each Cell In SearchRange
> Row = Cell.Row
> Column = Cell.Column
> If Cell.Value < -3 Or Cell.Value > 3 Then
> 'Output is placed in 2 columns, A for date, B for time
> ws2.Cells(x, 5).Value = ws.Cells(Row, 1).Value 'Copy-paste Date
> ws2.Cells(x, 6).Value = ws.Cells(1, Column).Value 'Copy-Paste Time
> x = x + 1
> End If Next Cell
>
> End Sub
Output with <-3 or >3
Dataset more left columns
excel
New contributor
add a comment |
up vote
-1
down vote
favorite
I am having data (image below) and task is to find values <3, identify what date and hour is and paste dates, hours in another spreadsheet of that cells. Does any have ideas?
Option Explicit
>
> Sub CopyPaste()
>
> Dim LastRow As Long, LastCol As Long, Row As Long, Column As Long, x
> As Long Dim wb As Workbook Dim ws As Worksheet, ws2 As Worksheet Dim
> SearchRange As Range, Cell As Range
>
> Set wb = ThisWorkbook Set ws = wb.Sheets("DataHorizontal") 'the sheet
> in which your data is Set ws2 = wb.Sheets("Overview") 'the sheet where
> you want your result
>
> LastRow = ws.Cells(Rows.Count, 1).End(xlUp).Row LastCol = ws.Cells(1,
> Columns.Count).End(xlToLeft).Column
>
> Set SearchRange = ws.Range(ws.Cells(2, 2), ws.Cells(LastRow, LastCol))
>
> x = 27
>
> For Each Cell In SearchRange
> Row = Cell.Row
> Column = Cell.Column
> If Cell.Value < -3 Or Cell.Value > 3 Then
> 'Output is placed in 2 columns, A for date, B for time
> ws2.Cells(x, 5).Value = ws.Cells(Row, 1).Value 'Copy-paste Date
> ws2.Cells(x, 6).Value = ws.Cells(1, Column).Value 'Copy-Paste Time
> x = x + 1
> End If Next Cell
>
> End Sub
Output with <-3 or >3
Dataset more left columns
excel
New contributor
add a comment |
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
I am having data (image below) and task is to find values <3, identify what date and hour is and paste dates, hours in another spreadsheet of that cells. Does any have ideas?
Option Explicit
>
> Sub CopyPaste()
>
> Dim LastRow As Long, LastCol As Long, Row As Long, Column As Long, x
> As Long Dim wb As Workbook Dim ws As Worksheet, ws2 As Worksheet Dim
> SearchRange As Range, Cell As Range
>
> Set wb = ThisWorkbook Set ws = wb.Sheets("DataHorizontal") 'the sheet
> in which your data is Set ws2 = wb.Sheets("Overview") 'the sheet where
> you want your result
>
> LastRow = ws.Cells(Rows.Count, 1).End(xlUp).Row LastCol = ws.Cells(1,
> Columns.Count).End(xlToLeft).Column
>
> Set SearchRange = ws.Range(ws.Cells(2, 2), ws.Cells(LastRow, LastCol))
>
> x = 27
>
> For Each Cell In SearchRange
> Row = Cell.Row
> Column = Cell.Column
> If Cell.Value < -3 Or Cell.Value > 3 Then
> 'Output is placed in 2 columns, A for date, B for time
> ws2.Cells(x, 5).Value = ws.Cells(Row, 1).Value 'Copy-paste Date
> ws2.Cells(x, 6).Value = ws.Cells(1, Column).Value 'Copy-Paste Time
> x = x + 1
> End If Next Cell
>
> End Sub
Output with <-3 or >3
Dataset more left columns
excel
New contributor
I am having data (image below) and task is to find values <3, identify what date and hour is and paste dates, hours in another spreadsheet of that cells. Does any have ideas?
Option Explicit
>
> Sub CopyPaste()
>
> Dim LastRow As Long, LastCol As Long, Row As Long, Column As Long, x
> As Long Dim wb As Workbook Dim ws As Worksheet, ws2 As Worksheet Dim
> SearchRange As Range, Cell As Range
>
> Set wb = ThisWorkbook Set ws = wb.Sheets("DataHorizontal") 'the sheet
> in which your data is Set ws2 = wb.Sheets("Overview") 'the sheet where
> you want your result
>
> LastRow = ws.Cells(Rows.Count, 1).End(xlUp).Row LastCol = ws.Cells(1,
> Columns.Count).End(xlToLeft).Column
>
> Set SearchRange = ws.Range(ws.Cells(2, 2), ws.Cells(LastRow, LastCol))
>
> x = 27
>
> For Each Cell In SearchRange
> Row = Cell.Row
> Column = Cell.Column
> If Cell.Value < -3 Or Cell.Value > 3 Then
> 'Output is placed in 2 columns, A for date, B for time
> ws2.Cells(x, 5).Value = ws.Cells(Row, 1).Value 'Copy-paste Date
> ws2.Cells(x, 6).Value = ws.Cells(1, Column).Value 'Copy-Paste Time
> x = x + 1
> End If Next Cell
>
> End Sub
Output with <-3 or >3
Dataset more left columns
excel
excel
New contributor
New contributor
edited Nov 11 at 9:04
New contributor
asked Nov 10 at 11:40
Vytautas Lukošiūnas
32
32
New contributor
New contributor
add a comment |
add a comment |
4 Answers
4
active
oldest
votes
up vote
0
down vote
accepted
You need a macro to do so.
Code example
Option Explicit
Sub CopyPaste()
Dim LastRow As Long, LastCol As Long, Row As Long, Column As Long, x As Long
Dim wb As Workbook
Dim ws As Worksheet, ws2 As Worksheet
Dim SearchRange As Range, Cell As Range
Set wb = ThisWorkbook
Set ws = wb.Sheets("input") 'the sheet in which your data is
Set ws2 = wb.Sheets("Output") 'the sheet where you want your result
LastRow = ws.Cells(Rows.Count, 1).End(xlUp).Row
LastCol = ws.Cells(1, Columns.Count).End(xlToLeft).Column
Set SearchRange = ws.Range(ws.Cells(2, 2), ws.Cells(LastRow, LastCol))
x = 2
For Each Cell In SearchRange
Row = Cell.Row
Column = Cell.Column
If Cell.Value < 3 Then
'Output is placed in 2 columns, A for time, B for date
ws2.Cells(x, 1).Value = ws.Cells(1, Column).Value 'Copy-Paste Time
ws2.Cells(x, 2).Value = ws.Cells(Row, 1).Value 'Copy-paste Date
x = x + 1
End If
Next Cell
End Sub
Thanks. It works without errors, but paste all dates, probably it's something wrong with formats. Trying to find solution.
– Vytautas Lukošiūnas
Nov 10 at 13:35
ok, can you please mark this answer as the correct one then? thanks
– Lambik
Nov 10 at 13:46
Sure, thanks a lot!
– Vytautas Lukošiūnas
Nov 10 at 14:19
Lambik, I am trying to modify one line to If Cell.Value < -3 Or Cell.Value >3 Then But then I get all dates, maybe you know where can be the problem? It would be goot to see <-3 and >3.
– Vytautas Lukošiūnas
Nov 10 at 14:58
please post the code you've written. if cell.value < -3 or cell.value > 3 then... should be correct.
– Lambik
Nov 10 at 15:05
|
show 6 more comments
up vote
0
down vote
Open the excel, press ALT+F11 and on the left side window, right click on the Worksheet you use (The name of the Worksheet can be found there), select Add -> Modul, and copy the following code into.
When you adjusted the variables, just press the Play button, or press F5.
Here is your solution:
Sub Stackoverflow()
Dim wbk1 As Workbook
Dim wbk2 As Workbook
Rem Creating a new workbook to collect data
Set wbk1 = ThisWorkbook
Set wbk2 = Workbooks.Add(xlWBATWorksheet)
Rem dc = datecolumn, the number of column AA
dc = Range("AA" & 1).Column
Rem k is the first row of new workbook, and i is the first row where the data can be found.
k = 1
i = 2
Do
j = Range("AB" & 1).Column
Do
If wbk1.Worksheets("Work1").Cells(i, j).Value < 3 Then
wbk2.Worksheets("Work1").Cells(k, 1) = wbk1.Worksheets("Work1").Cells(i, dc)
wbk2.Worksheets("Work1").Cells(k, 2) = wbk1.Worksheets("Work1").Cells(1, j)
wbk2.Worksheets("Work1").Cells(k, 3) = wbk1.Worksheets("Work1").Cells(i, j)
k = k + 1
End If
j = j + 1
Loop Until wbk1.Worksheets("Work1").Cells(i, j).Value = ""
i = i + 1
Loop Until wbk1.Worksheets("Work1").Cells(i, j).Value = ""
Rem the result will be:
Rem first column in the new workbook will be the date
Rem second is the time
Rem third is the data
End Sub
Since you haven't provided the row numbers on your screen, you have to set the 'i' value to the first row where the data can be found. So if the row number is 2 where the number data are, just leave it so.
Please also note, you have to rename Work1 to the name of your Worksheet!
Hope this will help!
New contributor
add a comment |
up vote
0
down vote
A faster way is using powerquery (Get & Transform Data
).
Format your source data as a table
, then use a query like this:
let
Source = Excel.CurrentWorkbook()[Name="Table1"][Content],
#"Unpivoted Other Columns" = Table.UnpivotOtherColumns(Source, "Date", "Time", "Value"),
#"Filtered Rows" = Table.SelectRows(#"Unpivoted Other Columns", each [Value] < 3),
#"Changed Type" = Table.TransformColumnTypes(#"Filtered Rows","Date", type date, "Time", type time, "Value", type number)
in
#"Changed Type"
add a comment |
up vote
0
down vote
Result will be like this, where you can adjust output table:
Idea is to loop through every column for a date, and print values. Then go to next date (row) and repeat the procedure. Output will printed out as in the one from Column BA to BC.
Sub CompareCopy()
Dim ws1 As Worksheet
Set ws1 = ActiveWorkbook.Worksheets("Sheet1")
Dim ws2 As Worksheet
Set ws2 = ActiveWorkbook.Worksheets("Sheet1") 'You can change the output datas sheet.
Dim lrow As Long
Dim i As Long
Dim j As Long
Dim lCol As Long
Dim k As Long
Dim Header1 As String
Dim Header2 As String
Dim Header3 As String
Dim ColumnOutput As String
k = 2 'first row where output data will be placed
lCol = ws1.Cells(1, Columns.Count).End(xlToLeft).Column 'find last column
lrow = ws1.Cells(Rows.Count, 27).End(xlUp).Row 'Find last row
ColumnOutput = lCol 'Set Column where output should start, default is the last column of your original table.
ws2.Cells(k - 1, ColumnOutput + 2) = "Date" 'Place where "Date" will be printed
ws2.Cells(k - 1, ColumnOutput + 3) = "Time" 'Place where "Time" will be printed
ws2.Cells(k - 1, ColumnOutput + 4) = "Value" 'Place where "Value" will be printed
For i = 2 To lrow 'Loop through each row
For j = 28 To lCol 'Loop through each Column
If -3 > ws1.Cells(i, j).Value Then 'If current table value is less than -3 then copy
ws2.Cells(k, ColumnOutput + 2).Value = ws1.Cells(i, 27).Value 'Copy Date
ws2.Cells(k, ColumnOutput + 2).NumberFormat = "dd-mmm-yy" 'Format time value to correct time
ws2.Cells(k, ColumnOutput + 3).Value = ws1.Cells(1, j).Value 'Copy Time
ws2.Cells(k, ColumnOutput + 3).NumberFormat = "hh:mm" 'Format time value to correct time
ws2.Cells(k, ColumnOutput + 4).Value = ws1.Cells(i, j).Value 'Copy Value
k = k + 1
End If
Next j
Next i
End Sub
add a comment |
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
You need a macro to do so.
Code example
Option Explicit
Sub CopyPaste()
Dim LastRow As Long, LastCol As Long, Row As Long, Column As Long, x As Long
Dim wb As Workbook
Dim ws As Worksheet, ws2 As Worksheet
Dim SearchRange As Range, Cell As Range
Set wb = ThisWorkbook
Set ws = wb.Sheets("input") 'the sheet in which your data is
Set ws2 = wb.Sheets("Output") 'the sheet where you want your result
LastRow = ws.Cells(Rows.Count, 1).End(xlUp).Row
LastCol = ws.Cells(1, Columns.Count).End(xlToLeft).Column
Set SearchRange = ws.Range(ws.Cells(2, 2), ws.Cells(LastRow, LastCol))
x = 2
For Each Cell In SearchRange
Row = Cell.Row
Column = Cell.Column
If Cell.Value < 3 Then
'Output is placed in 2 columns, A for time, B for date
ws2.Cells(x, 1).Value = ws.Cells(1, Column).Value 'Copy-Paste Time
ws2.Cells(x, 2).Value = ws.Cells(Row, 1).Value 'Copy-paste Date
x = x + 1
End If
Next Cell
End Sub
Thanks. It works without errors, but paste all dates, probably it's something wrong with formats. Trying to find solution.
– Vytautas Lukošiūnas
Nov 10 at 13:35
ok, can you please mark this answer as the correct one then? thanks
– Lambik
Nov 10 at 13:46
Sure, thanks a lot!
– Vytautas Lukošiūnas
Nov 10 at 14:19
Lambik, I am trying to modify one line to If Cell.Value < -3 Or Cell.Value >3 Then But then I get all dates, maybe you know where can be the problem? It would be goot to see <-3 and >3.
– Vytautas Lukošiūnas
Nov 10 at 14:58
please post the code you've written. if cell.value < -3 or cell.value > 3 then... should be correct.
– Lambik
Nov 10 at 15:05
|
show 6 more comments
up vote
0
down vote
accepted
You need a macro to do so.
Code example
Option Explicit
Sub CopyPaste()
Dim LastRow As Long, LastCol As Long, Row As Long, Column As Long, x As Long
Dim wb As Workbook
Dim ws As Worksheet, ws2 As Worksheet
Dim SearchRange As Range, Cell As Range
Set wb = ThisWorkbook
Set ws = wb.Sheets("input") 'the sheet in which your data is
Set ws2 = wb.Sheets("Output") 'the sheet where you want your result
LastRow = ws.Cells(Rows.Count, 1).End(xlUp).Row
LastCol = ws.Cells(1, Columns.Count).End(xlToLeft).Column
Set SearchRange = ws.Range(ws.Cells(2, 2), ws.Cells(LastRow, LastCol))
x = 2
For Each Cell In SearchRange
Row = Cell.Row
Column = Cell.Column
If Cell.Value < 3 Then
'Output is placed in 2 columns, A for time, B for date
ws2.Cells(x, 1).Value = ws.Cells(1, Column).Value 'Copy-Paste Time
ws2.Cells(x, 2).Value = ws.Cells(Row, 1).Value 'Copy-paste Date
x = x + 1
End If
Next Cell
End Sub
Thanks. It works without errors, but paste all dates, probably it's something wrong with formats. Trying to find solution.
– Vytautas Lukošiūnas
Nov 10 at 13:35
ok, can you please mark this answer as the correct one then? thanks
– Lambik
Nov 10 at 13:46
Sure, thanks a lot!
– Vytautas Lukošiūnas
Nov 10 at 14:19
Lambik, I am trying to modify one line to If Cell.Value < -3 Or Cell.Value >3 Then But then I get all dates, maybe you know where can be the problem? It would be goot to see <-3 and >3.
– Vytautas Lukošiūnas
Nov 10 at 14:58
please post the code you've written. if cell.value < -3 or cell.value > 3 then... should be correct.
– Lambik
Nov 10 at 15:05
|
show 6 more comments
up vote
0
down vote
accepted
up vote
0
down vote
accepted
You need a macro to do so.
Code example
Option Explicit
Sub CopyPaste()
Dim LastRow As Long, LastCol As Long, Row As Long, Column As Long, x As Long
Dim wb As Workbook
Dim ws As Worksheet, ws2 As Worksheet
Dim SearchRange As Range, Cell As Range
Set wb = ThisWorkbook
Set ws = wb.Sheets("input") 'the sheet in which your data is
Set ws2 = wb.Sheets("Output") 'the sheet where you want your result
LastRow = ws.Cells(Rows.Count, 1).End(xlUp).Row
LastCol = ws.Cells(1, Columns.Count).End(xlToLeft).Column
Set SearchRange = ws.Range(ws.Cells(2, 2), ws.Cells(LastRow, LastCol))
x = 2
For Each Cell In SearchRange
Row = Cell.Row
Column = Cell.Column
If Cell.Value < 3 Then
'Output is placed in 2 columns, A for time, B for date
ws2.Cells(x, 1).Value = ws.Cells(1, Column).Value 'Copy-Paste Time
ws2.Cells(x, 2).Value = ws.Cells(Row, 1).Value 'Copy-paste Date
x = x + 1
End If
Next Cell
End Sub
You need a macro to do so.
Code example
Option Explicit
Sub CopyPaste()
Dim LastRow As Long, LastCol As Long, Row As Long, Column As Long, x As Long
Dim wb As Workbook
Dim ws As Worksheet, ws2 As Worksheet
Dim SearchRange As Range, Cell As Range
Set wb = ThisWorkbook
Set ws = wb.Sheets("input") 'the sheet in which your data is
Set ws2 = wb.Sheets("Output") 'the sheet where you want your result
LastRow = ws.Cells(Rows.Count, 1).End(xlUp).Row
LastCol = ws.Cells(1, Columns.Count).End(xlToLeft).Column
Set SearchRange = ws.Range(ws.Cells(2, 2), ws.Cells(LastRow, LastCol))
x = 2
For Each Cell In SearchRange
Row = Cell.Row
Column = Cell.Column
If Cell.Value < 3 Then
'Output is placed in 2 columns, A for time, B for date
ws2.Cells(x, 1).Value = ws.Cells(1, Column).Value 'Copy-Paste Time
ws2.Cells(x, 2).Value = ws.Cells(Row, 1).Value 'Copy-paste Date
x = x + 1
End If
Next Cell
End Sub
answered Nov 10 at 12:35
Lambik
28819
28819
Thanks. It works without errors, but paste all dates, probably it's something wrong with formats. Trying to find solution.
– Vytautas Lukošiūnas
Nov 10 at 13:35
ok, can you please mark this answer as the correct one then? thanks
– Lambik
Nov 10 at 13:46
Sure, thanks a lot!
– Vytautas Lukošiūnas
Nov 10 at 14:19
Lambik, I am trying to modify one line to If Cell.Value < -3 Or Cell.Value >3 Then But then I get all dates, maybe you know where can be the problem? It would be goot to see <-3 and >3.
– Vytautas Lukošiūnas
Nov 10 at 14:58
please post the code you've written. if cell.value < -3 or cell.value > 3 then... should be correct.
– Lambik
Nov 10 at 15:05
|
show 6 more comments
Thanks. It works without errors, but paste all dates, probably it's something wrong with formats. Trying to find solution.
– Vytautas Lukošiūnas
Nov 10 at 13:35
ok, can you please mark this answer as the correct one then? thanks
– Lambik
Nov 10 at 13:46
Sure, thanks a lot!
– Vytautas Lukošiūnas
Nov 10 at 14:19
Lambik, I am trying to modify one line to If Cell.Value < -3 Or Cell.Value >3 Then But then I get all dates, maybe you know where can be the problem? It would be goot to see <-3 and >3.
– Vytautas Lukošiūnas
Nov 10 at 14:58
please post the code you've written. if cell.value < -3 or cell.value > 3 then... should be correct.
– Lambik
Nov 10 at 15:05
Thanks. It works without errors, but paste all dates, probably it's something wrong with formats. Trying to find solution.
– Vytautas Lukošiūnas
Nov 10 at 13:35
Thanks. It works without errors, but paste all dates, probably it's something wrong with formats. Trying to find solution.
– Vytautas Lukošiūnas
Nov 10 at 13:35
ok, can you please mark this answer as the correct one then? thanks
– Lambik
Nov 10 at 13:46
ok, can you please mark this answer as the correct one then? thanks
– Lambik
Nov 10 at 13:46
Sure, thanks a lot!
– Vytautas Lukošiūnas
Nov 10 at 14:19
Sure, thanks a lot!
– Vytautas Lukošiūnas
Nov 10 at 14:19
Lambik, I am trying to modify one line to If Cell.Value < -3 Or Cell.Value >3 Then But then I get all dates, maybe you know where can be the problem? It would be goot to see <-3 and >3.
– Vytautas Lukošiūnas
Nov 10 at 14:58
Lambik, I am trying to modify one line to If Cell.Value < -3 Or Cell.Value >3 Then But then I get all dates, maybe you know where can be the problem? It would be goot to see <-3 and >3.
– Vytautas Lukošiūnas
Nov 10 at 14:58
please post the code you've written. if cell.value < -3 or cell.value > 3 then... should be correct.
– Lambik
Nov 10 at 15:05
please post the code you've written. if cell.value < -3 or cell.value > 3 then... should be correct.
– Lambik
Nov 10 at 15:05
|
show 6 more comments
up vote
0
down vote
Open the excel, press ALT+F11 and on the left side window, right click on the Worksheet you use (The name of the Worksheet can be found there), select Add -> Modul, and copy the following code into.
When you adjusted the variables, just press the Play button, or press F5.
Here is your solution:
Sub Stackoverflow()
Dim wbk1 As Workbook
Dim wbk2 As Workbook
Rem Creating a new workbook to collect data
Set wbk1 = ThisWorkbook
Set wbk2 = Workbooks.Add(xlWBATWorksheet)
Rem dc = datecolumn, the number of column AA
dc = Range("AA" & 1).Column
Rem k is the first row of new workbook, and i is the first row where the data can be found.
k = 1
i = 2
Do
j = Range("AB" & 1).Column
Do
If wbk1.Worksheets("Work1").Cells(i, j).Value < 3 Then
wbk2.Worksheets("Work1").Cells(k, 1) = wbk1.Worksheets("Work1").Cells(i, dc)
wbk2.Worksheets("Work1").Cells(k, 2) = wbk1.Worksheets("Work1").Cells(1, j)
wbk2.Worksheets("Work1").Cells(k, 3) = wbk1.Worksheets("Work1").Cells(i, j)
k = k + 1
End If
j = j + 1
Loop Until wbk1.Worksheets("Work1").Cells(i, j).Value = ""
i = i + 1
Loop Until wbk1.Worksheets("Work1").Cells(i, j).Value = ""
Rem the result will be:
Rem first column in the new workbook will be the date
Rem second is the time
Rem third is the data
End Sub
Since you haven't provided the row numbers on your screen, you have to set the 'i' value to the first row where the data can be found. So if the row number is 2 where the number data are, just leave it so.
Please also note, you have to rename Work1 to the name of your Worksheet!
Hope this will help!
New contributor
add a comment |
up vote
0
down vote
Open the excel, press ALT+F11 and on the left side window, right click on the Worksheet you use (The name of the Worksheet can be found there), select Add -> Modul, and copy the following code into.
When you adjusted the variables, just press the Play button, or press F5.
Here is your solution:
Sub Stackoverflow()
Dim wbk1 As Workbook
Dim wbk2 As Workbook
Rem Creating a new workbook to collect data
Set wbk1 = ThisWorkbook
Set wbk2 = Workbooks.Add(xlWBATWorksheet)
Rem dc = datecolumn, the number of column AA
dc = Range("AA" & 1).Column
Rem k is the first row of new workbook, and i is the first row where the data can be found.
k = 1
i = 2
Do
j = Range("AB" & 1).Column
Do
If wbk1.Worksheets("Work1").Cells(i, j).Value < 3 Then
wbk2.Worksheets("Work1").Cells(k, 1) = wbk1.Worksheets("Work1").Cells(i, dc)
wbk2.Worksheets("Work1").Cells(k, 2) = wbk1.Worksheets("Work1").Cells(1, j)
wbk2.Worksheets("Work1").Cells(k, 3) = wbk1.Worksheets("Work1").Cells(i, j)
k = k + 1
End If
j = j + 1
Loop Until wbk1.Worksheets("Work1").Cells(i, j).Value = ""
i = i + 1
Loop Until wbk1.Worksheets("Work1").Cells(i, j).Value = ""
Rem the result will be:
Rem first column in the new workbook will be the date
Rem second is the time
Rem third is the data
End Sub
Since you haven't provided the row numbers on your screen, you have to set the 'i' value to the first row where the data can be found. So if the row number is 2 where the number data are, just leave it so.
Please also note, you have to rename Work1 to the name of your Worksheet!
Hope this will help!
New contributor
add a comment |
up vote
0
down vote
up vote
0
down vote
Open the excel, press ALT+F11 and on the left side window, right click on the Worksheet you use (The name of the Worksheet can be found there), select Add -> Modul, and copy the following code into.
When you adjusted the variables, just press the Play button, or press F5.
Here is your solution:
Sub Stackoverflow()
Dim wbk1 As Workbook
Dim wbk2 As Workbook
Rem Creating a new workbook to collect data
Set wbk1 = ThisWorkbook
Set wbk2 = Workbooks.Add(xlWBATWorksheet)
Rem dc = datecolumn, the number of column AA
dc = Range("AA" & 1).Column
Rem k is the first row of new workbook, and i is the first row where the data can be found.
k = 1
i = 2
Do
j = Range("AB" & 1).Column
Do
If wbk1.Worksheets("Work1").Cells(i, j).Value < 3 Then
wbk2.Worksheets("Work1").Cells(k, 1) = wbk1.Worksheets("Work1").Cells(i, dc)
wbk2.Worksheets("Work1").Cells(k, 2) = wbk1.Worksheets("Work1").Cells(1, j)
wbk2.Worksheets("Work1").Cells(k, 3) = wbk1.Worksheets("Work1").Cells(i, j)
k = k + 1
End If
j = j + 1
Loop Until wbk1.Worksheets("Work1").Cells(i, j).Value = ""
i = i + 1
Loop Until wbk1.Worksheets("Work1").Cells(i, j).Value = ""
Rem the result will be:
Rem first column in the new workbook will be the date
Rem second is the time
Rem third is the data
End Sub
Since you haven't provided the row numbers on your screen, you have to set the 'i' value to the first row where the data can be found. So if the row number is 2 where the number data are, just leave it so.
Please also note, you have to rename Work1 to the name of your Worksheet!
Hope this will help!
New contributor
Open the excel, press ALT+F11 and on the left side window, right click on the Worksheet you use (The name of the Worksheet can be found there), select Add -> Modul, and copy the following code into.
When you adjusted the variables, just press the Play button, or press F5.
Here is your solution:
Sub Stackoverflow()
Dim wbk1 As Workbook
Dim wbk2 As Workbook
Rem Creating a new workbook to collect data
Set wbk1 = ThisWorkbook
Set wbk2 = Workbooks.Add(xlWBATWorksheet)
Rem dc = datecolumn, the number of column AA
dc = Range("AA" & 1).Column
Rem k is the first row of new workbook, and i is the first row where the data can be found.
k = 1
i = 2
Do
j = Range("AB" & 1).Column
Do
If wbk1.Worksheets("Work1").Cells(i, j).Value < 3 Then
wbk2.Worksheets("Work1").Cells(k, 1) = wbk1.Worksheets("Work1").Cells(i, dc)
wbk2.Worksheets("Work1").Cells(k, 2) = wbk1.Worksheets("Work1").Cells(1, j)
wbk2.Worksheets("Work1").Cells(k, 3) = wbk1.Worksheets("Work1").Cells(i, j)
k = k + 1
End If
j = j + 1
Loop Until wbk1.Worksheets("Work1").Cells(i, j).Value = ""
i = i + 1
Loop Until wbk1.Worksheets("Work1").Cells(i, j).Value = ""
Rem the result will be:
Rem first column in the new workbook will be the date
Rem second is the time
Rem third is the data
End Sub
Since you haven't provided the row numbers on your screen, you have to set the 'i' value to the first row where the data can be found. So if the row number is 2 where the number data are, just leave it so.
Please also note, you have to rename Work1 to the name of your Worksheet!
Hope this will help!
New contributor
New contributor
answered Nov 10 at 12:34
sdda
12
12
New contributor
New contributor
add a comment |
add a comment |
up vote
0
down vote
A faster way is using powerquery (Get & Transform Data
).
Format your source data as a table
, then use a query like this:
let
Source = Excel.CurrentWorkbook()[Name="Table1"][Content],
#"Unpivoted Other Columns" = Table.UnpivotOtherColumns(Source, "Date", "Time", "Value"),
#"Filtered Rows" = Table.SelectRows(#"Unpivoted Other Columns", each [Value] < 3),
#"Changed Type" = Table.TransformColumnTypes(#"Filtered Rows","Date", type date, "Time", type time, "Value", type number)
in
#"Changed Type"
add a comment |
up vote
0
down vote
A faster way is using powerquery (Get & Transform Data
).
Format your source data as a table
, then use a query like this:
let
Source = Excel.CurrentWorkbook()[Name="Table1"][Content],
#"Unpivoted Other Columns" = Table.UnpivotOtherColumns(Source, "Date", "Time", "Value"),
#"Filtered Rows" = Table.SelectRows(#"Unpivoted Other Columns", each [Value] < 3),
#"Changed Type" = Table.TransformColumnTypes(#"Filtered Rows","Date", type date, "Time", type time, "Value", type number)
in
#"Changed Type"
add a comment |
up vote
0
down vote
up vote
0
down vote
A faster way is using powerquery (Get & Transform Data
).
Format your source data as a table
, then use a query like this:
let
Source = Excel.CurrentWorkbook()[Name="Table1"][Content],
#"Unpivoted Other Columns" = Table.UnpivotOtherColumns(Source, "Date", "Time", "Value"),
#"Filtered Rows" = Table.SelectRows(#"Unpivoted Other Columns", each [Value] < 3),
#"Changed Type" = Table.TransformColumnTypes(#"Filtered Rows","Date", type date, "Time", type time, "Value", type number)
in
#"Changed Type"
A faster way is using powerquery (Get & Transform Data
).
Format your source data as a table
, then use a query like this:
let
Source = Excel.CurrentWorkbook()[Name="Table1"][Content],
#"Unpivoted Other Columns" = Table.UnpivotOtherColumns(Source, "Date", "Time", "Value"),
#"Filtered Rows" = Table.SelectRows(#"Unpivoted Other Columns", each [Value] < 3),
#"Changed Type" = Table.TransformColumnTypes(#"Filtered Rows","Date", type date, "Time", type time, "Value", type number)
in
#"Changed Type"
answered Nov 10 at 13:40
Olly
2,9571925
2,9571925
add a comment |
add a comment |
up vote
0
down vote
Result will be like this, where you can adjust output table:
Idea is to loop through every column for a date, and print values. Then go to next date (row) and repeat the procedure. Output will printed out as in the one from Column BA to BC.
Sub CompareCopy()
Dim ws1 As Worksheet
Set ws1 = ActiveWorkbook.Worksheets("Sheet1")
Dim ws2 As Worksheet
Set ws2 = ActiveWorkbook.Worksheets("Sheet1") 'You can change the output datas sheet.
Dim lrow As Long
Dim i As Long
Dim j As Long
Dim lCol As Long
Dim k As Long
Dim Header1 As String
Dim Header2 As String
Dim Header3 As String
Dim ColumnOutput As String
k = 2 'first row where output data will be placed
lCol = ws1.Cells(1, Columns.Count).End(xlToLeft).Column 'find last column
lrow = ws1.Cells(Rows.Count, 27).End(xlUp).Row 'Find last row
ColumnOutput = lCol 'Set Column where output should start, default is the last column of your original table.
ws2.Cells(k - 1, ColumnOutput + 2) = "Date" 'Place where "Date" will be printed
ws2.Cells(k - 1, ColumnOutput + 3) = "Time" 'Place where "Time" will be printed
ws2.Cells(k - 1, ColumnOutput + 4) = "Value" 'Place where "Value" will be printed
For i = 2 To lrow 'Loop through each row
For j = 28 To lCol 'Loop through each Column
If -3 > ws1.Cells(i, j).Value Then 'If current table value is less than -3 then copy
ws2.Cells(k, ColumnOutput + 2).Value = ws1.Cells(i, 27).Value 'Copy Date
ws2.Cells(k, ColumnOutput + 2).NumberFormat = "dd-mmm-yy" 'Format time value to correct time
ws2.Cells(k, ColumnOutput + 3).Value = ws1.Cells(1, j).Value 'Copy Time
ws2.Cells(k, ColumnOutput + 3).NumberFormat = "hh:mm" 'Format time value to correct time
ws2.Cells(k, ColumnOutput + 4).Value = ws1.Cells(i, j).Value 'Copy Value
k = k + 1
End If
Next j
Next i
End Sub
add a comment |
up vote
0
down vote
Result will be like this, where you can adjust output table:
Idea is to loop through every column for a date, and print values. Then go to next date (row) and repeat the procedure. Output will printed out as in the one from Column BA to BC.
Sub CompareCopy()
Dim ws1 As Worksheet
Set ws1 = ActiveWorkbook.Worksheets("Sheet1")
Dim ws2 As Worksheet
Set ws2 = ActiveWorkbook.Worksheets("Sheet1") 'You can change the output datas sheet.
Dim lrow As Long
Dim i As Long
Dim j As Long
Dim lCol As Long
Dim k As Long
Dim Header1 As String
Dim Header2 As String
Dim Header3 As String
Dim ColumnOutput As String
k = 2 'first row where output data will be placed
lCol = ws1.Cells(1, Columns.Count).End(xlToLeft).Column 'find last column
lrow = ws1.Cells(Rows.Count, 27).End(xlUp).Row 'Find last row
ColumnOutput = lCol 'Set Column where output should start, default is the last column of your original table.
ws2.Cells(k - 1, ColumnOutput + 2) = "Date" 'Place where "Date" will be printed
ws2.Cells(k - 1, ColumnOutput + 3) = "Time" 'Place where "Time" will be printed
ws2.Cells(k - 1, ColumnOutput + 4) = "Value" 'Place where "Value" will be printed
For i = 2 To lrow 'Loop through each row
For j = 28 To lCol 'Loop through each Column
If -3 > ws1.Cells(i, j).Value Then 'If current table value is less than -3 then copy
ws2.Cells(k, ColumnOutput + 2).Value = ws1.Cells(i, 27).Value 'Copy Date
ws2.Cells(k, ColumnOutput + 2).NumberFormat = "dd-mmm-yy" 'Format time value to correct time
ws2.Cells(k, ColumnOutput + 3).Value = ws1.Cells(1, j).Value 'Copy Time
ws2.Cells(k, ColumnOutput + 3).NumberFormat = "hh:mm" 'Format time value to correct time
ws2.Cells(k, ColumnOutput + 4).Value = ws1.Cells(i, j).Value 'Copy Value
k = k + 1
End If
Next j
Next i
End Sub
add a comment |
up vote
0
down vote
up vote
0
down vote
Result will be like this, where you can adjust output table:
Idea is to loop through every column for a date, and print values. Then go to next date (row) and repeat the procedure. Output will printed out as in the one from Column BA to BC.
Sub CompareCopy()
Dim ws1 As Worksheet
Set ws1 = ActiveWorkbook.Worksheets("Sheet1")
Dim ws2 As Worksheet
Set ws2 = ActiveWorkbook.Worksheets("Sheet1") 'You can change the output datas sheet.
Dim lrow As Long
Dim i As Long
Dim j As Long
Dim lCol As Long
Dim k As Long
Dim Header1 As String
Dim Header2 As String
Dim Header3 As String
Dim ColumnOutput As String
k = 2 'first row where output data will be placed
lCol = ws1.Cells(1, Columns.Count).End(xlToLeft).Column 'find last column
lrow = ws1.Cells(Rows.Count, 27).End(xlUp).Row 'Find last row
ColumnOutput = lCol 'Set Column where output should start, default is the last column of your original table.
ws2.Cells(k - 1, ColumnOutput + 2) = "Date" 'Place where "Date" will be printed
ws2.Cells(k - 1, ColumnOutput + 3) = "Time" 'Place where "Time" will be printed
ws2.Cells(k - 1, ColumnOutput + 4) = "Value" 'Place where "Value" will be printed
For i = 2 To lrow 'Loop through each row
For j = 28 To lCol 'Loop through each Column
If -3 > ws1.Cells(i, j).Value Then 'If current table value is less than -3 then copy
ws2.Cells(k, ColumnOutput + 2).Value = ws1.Cells(i, 27).Value 'Copy Date
ws2.Cells(k, ColumnOutput + 2).NumberFormat = "dd-mmm-yy" 'Format time value to correct time
ws2.Cells(k, ColumnOutput + 3).Value = ws1.Cells(1, j).Value 'Copy Time
ws2.Cells(k, ColumnOutput + 3).NumberFormat = "hh:mm" 'Format time value to correct time
ws2.Cells(k, ColumnOutput + 4).Value = ws1.Cells(i, j).Value 'Copy Value
k = k + 1
End If
Next j
Next i
End Sub
Result will be like this, where you can adjust output table:
Idea is to loop through every column for a date, and print values. Then go to next date (row) and repeat the procedure. Output will printed out as in the one from Column BA to BC.
Sub CompareCopy()
Dim ws1 As Worksheet
Set ws1 = ActiveWorkbook.Worksheets("Sheet1")
Dim ws2 As Worksheet
Set ws2 = ActiveWorkbook.Worksheets("Sheet1") 'You can change the output datas sheet.
Dim lrow As Long
Dim i As Long
Dim j As Long
Dim lCol As Long
Dim k As Long
Dim Header1 As String
Dim Header2 As String
Dim Header3 As String
Dim ColumnOutput As String
k = 2 'first row where output data will be placed
lCol = ws1.Cells(1, Columns.Count).End(xlToLeft).Column 'find last column
lrow = ws1.Cells(Rows.Count, 27).End(xlUp).Row 'Find last row
ColumnOutput = lCol 'Set Column where output should start, default is the last column of your original table.
ws2.Cells(k - 1, ColumnOutput + 2) = "Date" 'Place where "Date" will be printed
ws2.Cells(k - 1, ColumnOutput + 3) = "Time" 'Place where "Time" will be printed
ws2.Cells(k - 1, ColumnOutput + 4) = "Value" 'Place where "Value" will be printed
For i = 2 To lrow 'Loop through each row
For j = 28 To lCol 'Loop through each Column
If -3 > ws1.Cells(i, j).Value Then 'If current table value is less than -3 then copy
ws2.Cells(k, ColumnOutput + 2).Value = ws1.Cells(i, 27).Value 'Copy Date
ws2.Cells(k, ColumnOutput + 2).NumberFormat = "dd-mmm-yy" 'Format time value to correct time
ws2.Cells(k, ColumnOutput + 3).Value = ws1.Cells(1, j).Value 'Copy Time
ws2.Cells(k, ColumnOutput + 3).NumberFormat = "hh:mm" 'Format time value to correct time
ws2.Cells(k, ColumnOutput + 4).Value = ws1.Cells(i, j).Value 'Copy Value
k = k + 1
End If
Next j
Next i
End Sub
edited Nov 10 at 14:03
answered Nov 10 at 12:56
Wizhi
3,1921727
3,1921727
add a comment |
add a comment |
Vytautas Lukošiūnas is a new contributor. Be nice, and check out our Code of Conduct.
Vytautas Lukošiūnas is a new contributor. Be nice, and check out our Code of Conduct.
Vytautas Lukošiūnas is a new contributor. Be nice, and check out our Code of Conduct.
Vytautas Lukošiūnas is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53238565%2fexcel-find-smaller-values-than-x-identify-date-time-and-paste-it%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password