Results 1 to 6 of 6

Manipulate dataset in a quarterly format

Threaded View

telas Manipulate dataset in a... 01-06-2017, 06:36 AM
pjwhitfield Re: Little VBA programming... 01-06-2017, 06:56 AM
telas Re: Little VBA programming... 01-06-2017, 12:07 PM
FDibbins Re: Little VBA programming... 01-06-2017, 12:28 PM
telas Re: Little VBA programming... 01-06-2017, 05:09 PM
pjwhitfield Re: Manipulate dataset in a... 01-10-2017, 05:48 AM
  1. #1
    Registered User
    Join Date
    01-06-2017
    Location
    patagonia
    MS-Off Ver
    Professional Plus 2013
    Posts
    6

    Manipulate dataset in a quarterly format

    Dear All,

    I am new VBA user and I would like your help because I am getting crazy. I am using a data set with 2 columns. In the first one I have the years (1970-2013) and in the second column the month of an event. What I am trying to do is to manipulate these two columns and create a third one collecting the number of these events in a quarterly form. For the quarters that no event has been occurred I just put a 0 for them.

    The problem is that my code is working fine until it meets a missing year. There is something wrong and I CANT SEE IT. Can anyone help me with it please?? I have attached my data set. Much appreciated.

    Sub Number_of_Crisis()
    
    With ActiveSheet
        lastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
    End With
    
    Dat = 1970
    g = 1
    
    For p = 1 To lastRow
    
    If Cells(p, 1) = Dat Then
         Cells(g, 4).Name = "Quarter1"
         Cells(g + 1, 4).Name = "Quarter2"
         Cells(g + 2, 4).Name = "Quarter3"
         Cells(g + 3, 4).Name = "Quarter4"
         
         If Cells(p, 2) <= 3 Then
           Range("Quarter1").Value = Range("Quarter1").Value + 1
          ElseIf Cells(p, 2) > 3 And Cells(p, 2) < 7 Then
           Range("Quarter2").Value = Range("Quarter2").Value + 1
          ElseIf Cells(p, 2) > 6 And Cells(p, 2) < 10 Then
           Range("Quarter3").Value = Range("Quarter3").Value + 1
          ElseIf Cells(p, 2) > 9 And Cells(p, 2) < 13 Then
           Range("Quarter4").Value = Range("Quarter4").Value + 1
         End If
       
    ElseIf Cells(p, 1) = Dat + 1 Then
          Dat = Dat + 1
          g = g + 4
          Cells(g, 4).Name = "Quarter1"
          Cells(g + 1, 4).Name = "Quarter2"
          Cells(g + 2, 4).Name = "Quarter3"
          Cells(g + 3, 4).Name = "Quarter4"
          
         If Cells(p, 2) <= 3 Then
           Range("Quarter1").Value = Range("Quarter1").Value + 1
         ElseIf Cells(p, 2) > 3 And Cells(p, 2) < 7 Then
           Range("Quarter2").Value = Range("Quarter2").Value + 1
         ElseIf Cells(p, 2) > 6 And Cells(p, 2) < 10 Then
           Range("Quarter3").Value = Range("Quarter3").Value + 1
         ElseIf Cells(p, 2) > 9 And Cells(p, 2) < 13 Then
           Range("Quarter4").Value = Range("Quarter4").Value + 1
         End If
         
    ElseIf Cells(p, 1) <> Dat Then
         Dat = Dat + 1
         g = g + 4
         Cells(g, 4).Name = "Quarter1"
         Cells(g + 1, 4).Name = "Quarter2"
         Cells(g + 2, 4).Name = "Quarter3"
         Cells(g + 3, 4).Name = "Quarter4"
         
    End If
    
    Next p
    
    telas = (Dat - 1970 + 1) * 4
    
    For tel = 1 To telas
      If Cells(tel, 4) = "" Then
         Cells(tel, 4) = 0
      End If
    Next tel
      
    End Sub
    Attached Files Attached Files
    Last edited by telas; 01-06-2017 at 04:26 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. vba programming-xl
    By grkchakri in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-19-2012, 11:50 PM
  2. VBA Programming
    By Dr.Levis in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-24-2012, 09:36 AM
  3. Programming without VBA?
    By jesperhs in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-10-2010, 09:44 AM
  4. Help with programming...
    By FooFghtrs33 in forum Excel General
    Replies: 1
    Last Post: 05-06-2009, 02:45 PM
  5. VBA programming
    By kush28 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-09-2006, 04:05 AM
  6. [SOLVED] Programming help
    By BB in forum Excel General
    Replies: 3
    Last Post: 12-04-2005, 09:15 PM
  7. [SOLVED] Programming Help???
    By Moonraker in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-29-2005, 01:05 AM
  8. [SOLVED] Programming
    By Javad in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-29-2005, 06:06 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1