Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Data Convertion

Posted on 2014-02-23
17
Medium Priority
?
244 Views
Last Modified: 2014-02-25
Hi Experts,

I have one WB which convert 1 min data to 15 Min data on Button click.
I need modification in Code which include only data between 9:15 AM To 15:30 PM while converting 1 min to 15 min.

Thanks
Data-Convert-V02.xlsm
0
Comment
Question by:Naresh Patel
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 5
  • 4
17 Comments
 
LVL 53

Expert Comment

by:Rgonzo1971
ID: 39881848
Hi,

pls try

Option Explicit

Sub Convert_1to15()
Dim WS As Worksheet
Dim WSConv As Worksheet
Dim MaxRow As Long, MaxRowConv As Long, I As Long, J As Long, Incr As Long, StandardIncr As Long
Dim StRow As Long, EndRow As Long

Set WS = ActiveSheet
MaxRow = WS.UsedRange.Rows.Count

'---> Check if Sheet 15 Min there
On Error Resume Next
Set WSConv = Sheets("15 Min")
If Err <> 0 Then
    Worksheets.Add after:=Worksheets(Worksheets.Count)
    Set WSConv = ActiveSheet
    WSConv.Name = "15 Min"
    WS.Range("1:1").Copy WSConv.Range("A1")
    WS.Range("A:A").Copy
    WSConv.Range("A1").PasteSpecial xlPasteFormats
    MaxRowConv = 2
Else
    MaxRowConv = WSConv.UsedRange.Rows.Count + 1
End If
On Error GoTo 0

StandardIncr = 14
Incr = StandardIncr
'---> Start Process
For I = 2 + Incr To MaxRow Step Incr + 1
    If I <> 2 + StandardIncr Then
        '---> Check to see if Current set of dates falls all within the same date
        If (TimeValue(WS.Cells(I - Incr, "A")) > TimeValue("15:30:00") And _
            DateValue(WS.Cells(I - Incr, "A")) <> DateValue(WS.Cells(I, "A"))) Then
            I = I + 1
        ElseIf DateValue(WS.Cells(I - Incr, "A")) <> DateValue(WS.Cells(I, "A")) Then
            
            J = I - Incr
            Do While TimeValue(WS.Cells(J, "A")) <= TimeValue("15:30:00")
                J = J + 1
            Loop

            Incr = J - 1 - (I - Incr)
            I = I - StandardIncr
        Else
            Incr = StandardIncr
        End If
    End If
    
    WSConv.Cells(MaxRowConv, "A") = WS.Cells(I, "A")
    WSConv.Cells(MaxRowConv, "B") = WS.Cells(I - Incr, "B")
    WSConv.Cells(MaxRowConv, "C") = WS.Application.WorksheetFunction.Max(WS.Range("C" & I - Incr & ":C" & I))
    WSConv.Cells(MaxRowConv, "D") = WS.Application.WorksheetFunction.Min(WS.Range("D" & I - Incr & ":D" & I))
    WSConv.Cells(MaxRowConv, "E") = WS.Cells(I, "E")
    WSConv.Cells(MaxRowConv, "F") = WS.Application.WorksheetFunction.Sum(WS.Range("F" & I - Incr & ":F" & I))
    MaxRowConv = MaxRowConv + 1
    Incr = StandardIncr
    
Next I
End Sub

Open in new window

EDIT Code Edited

Regards
0
 
LVL 8

Author Comment

by:Naresh Patel
ID: 39881869
Yes Perfect. Only One Thing After Sub End There Is Selection Left In Source Sheet - 1 Min Sheet.


Thanks
0
 
LVL 53

Expert Comment

by:Rgonzo1971
ID: 39881872
Could you explain?
0
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 
LVL 8

Author Comment

by:Naresh Patel
ID: 39881886
Now Two ThingsBy Selection Mean @ EndIf i delete some rows in sheet 15 min and again click on button - No result - have to overpast on actual data and fill deleted data.
Thanks
0
 
LVL 53

Expert Comment

by:Rgonzo1971
ID: 39881894
HI

First Problem solved

the code is designed to add at the end of list the data in 1 min not to replace it

Regards
0
 
LVL 8

Author Comment

by:Naresh Patel
ID: 39881899
may I have this modification which over past on data ?    Thanks
0
 
LVL 53

Accepted Solution

by:
Rgonzo1971 earned 2000 total points
ID: 39881917
To replace the data

use

Option Explicit

Sub Convert_1to15()
Dim WS As Worksheet
Dim WSConv As Worksheet
Dim MaxRow As Long, MaxRowConv As Long, I As Long, J As Long, Incr As Long, StandardIncr As Long
Dim StRow As Long, EndRow As Long
Application.ScreenUpdating = False
Set WS = ActiveSheet
MaxRow = WS.UsedRange.Rows.Count

'---> Check if Sheet 15 Min there
On Error Resume Next
Set WSConv = Sheets("15 Min")
If Err <> 0 Then
    Worksheets.Add after:=Worksheets(Worksheets.Count)
    Set WSConv = ActiveSheet
    WSConv.Name = "15 Min"
    WS.Range("1:1").Copy WSConv.Range("A1")
    WS.Range("A:A").Copy
    WSConv.Range("A1").PasteSpecial xlPasteFormats
    MaxRowConv = 2
    Application.CutCopyMode = False
Else
    WSConv.Rows("2:" & Rows.Count).EntireRow.ClearContents
    MaxRowConv = WSConv.UsedRange.Rows.Count + 1
End If
On Error GoTo 0
Application.ScreenUpdating = False
StandardIncr = 14
Incr = StandardIncr
'---> Start Process
For I = 2 + Incr To MaxRow Step Incr + 1
    If I <> 2 + StandardIncr Then
        '---> Check to see if Current set of dates falls all within the same date
        If (TimeValue(WS.Cells(I - Incr, "A")) > TimeValue("15:30:00") And _
            DateValue(WS.Cells(I - Incr, "A")) <> DateValue(WS.Cells(I, "A"))) Then
            I = I + 1
        ElseIf DateValue(WS.Cells(I - Incr, "A")) <> DateValue(WS.Cells(I, "A")) Then
            
            J = I - Incr
            Do While TimeValue(WS.Cells(J, "A")) <= TimeValue("15:30:00")
                J = J + 1
            Loop

            Incr = J - 1 - (I - Incr)
            I = I - StandardIncr
        Else
            Incr = StandardIncr
        End If
    End If
    
    WSConv.Cells(MaxRowConv, "A") = WS.Cells(I, "A")
    WSConv.Cells(MaxRowConv, "B") = WS.Cells(I - Incr, "B")
    WSConv.Cells(MaxRowConv, "C") = WS.Application.WorksheetFunction.Max(WS.Range("C" & I - Incr & ":C" & I))
    WSConv.Cells(MaxRowConv, "D") = WS.Application.WorksheetFunction.Min(WS.Range("D" & I - Incr & ":D" & I))
    WSConv.Cells(MaxRowConv, "E") = WS.Cells(I, "E")
    WSConv.Cells(MaxRowConv, "F") = WS.Application.WorksheetFunction.Sum(WS.Range("F" & I - Incr & ":F" & I))
    MaxRowConv = MaxRowConv + 1
    Incr = StandardIncr
    
Next I
Application.ScreenUpdating = True
End Sub

Open in new window

Regards
0
 
LVL 8

Author Closing Comment

by:Naresh Patel
ID: 39881928
Thanks & Thanks For Quick Response
0
 
LVL 31

Expert Comment

by:gowflow
ID: 39882305
@itjockey

I think the proposed solution does not fit exactly your need !!! with all due respect although it fit the sample of data you provided that have time AFTER 15:30, it does not cater for data that is BEFORE 9:15

I have put Rgonzo1971 sub in the attached workbook and labeled it Convert_1to15_Rgonzo1971

Run it on the sample data that I added 4 lines in the beginning that covers 911 till 914 and you will see the results.

@Rgonzo1971 pls do not take these comments as addressed to you in any way.

Regards
gowflow
Data-Convert-V03.xlsm
0
 
LVL 8

Author Comment

by:Naresh Patel
ID: 39882337
I am on my way back to home. Sure I'll look in to this.
Thanks eagle eyes.   ;-)
0
 
LVL 53

Expert Comment

by:Rgonzo1971
ID: 39882347
Hi all

I thought it wasn't relevant since I supposed the data pulled would not have any data before 9:15

Regards
0
 
LVL 31

Expert Comment

by:gowflow
ID: 39882351
Well a macro is a macro and limitations are limitation. I know about it coz I worked on the intial macro and when it came that we needed to eliminate data outside the 9:15  15:30 I said that a different logic should be considered.

Anyway no big deal
gowflow
0
 
LVL 8

Author Comment

by:Naresh Patel
ID: 39884918
Yes Sir gowflow,

I had seen it include before 9:15 data too and I don't want that data in 15 min conversation.
so what you suggest ...I would like to post new question regarding this .......may I?


Thanks
0
 
LVL 31

Expert Comment

by:gowflow
ID: 39885152
I think this question is closed and feel if you want a 'correct' answer as the one posted may apply to your data posted however it does not apply to 'any data' that could have al lot of items before 9:15 and after 15:30 scattered. As I mentioned in my previous post a different approached is to be considered.

It is up to you, you know your business better, if you feel that these situations may never happen then this macro could do the job, if not then you may post a new question to make sure ONLY data in the desired frame is taken into consideration.

Let me know your decision.
gowflow
0
 
LVL 8

Author Comment

by:Naresh Patel
ID: 39885155
New Question Sir
0
 
LVL 31

Expert Comment

by:gowflow
ID: 39885158
ok fine pls post a link in here
gowflow
0
 
LVL 8

Author Comment

by:Naresh Patel
ID: 39885181
Here it is Data Convertion.


Thanks
0

Featured Post

Office 365 Training for IT Pros

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
Cancel future meetings from user mailboxes in Office 365 using Remove-CalendarEvents
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question