Add cell if

tuytuy

Board Regular
Joined
Mar 28, 2013
Messages
75
Hi,
I have a sheet that looks like this:
GSM numberExtensionGroup nameSubgroup nameName GSM numberUser ref1User Ref2Call dateCall timeCall durationDestinationZone/Country/OperatorTariffTypeSupplementary servicesIndicative tariffUsage amountCurrencyCountry of destinationAccount numberDiscount Indicator
Jan-13 xxxxxxxxxxxxUnfiled - Niet toegekend - Non attribué28-Jan-1316:58:5300:02:05478882664On SiteNormalCommunications nationales00EUR10736059N
Jan-13 xxxxxxxxxxxxUnfiled - Niet toegekend - Non attribué29-Jan-1316:47:2100:11:37493194255MobistarNormalCommunications nationalesR01.3803EUR10736059Y
Jan-13 xxxxxxxxxxxxUnfiled - Niet toegekend - Non attribué02-Jan-1321:31:2100:01:0031 111 483 392From SiteRéduitCommunications internationalesR00.06EUR10736059Y

<tbody>
</tbody>

i'd like to add up, using a macro, the "Usage amount" if the type is "Communication nationals" only.
 
and how can i work around that ?
i tried to separate both in 2 different macros and put at then end of the first one Application.Run but it still gives me the same error ...
 
Upvote 0

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
and how can i work around that ?
i tried to separate both in 2 different macros and put at then end of the first one Application.Run but it still gives me the same error ...
No, do not create two separate macros... just delete one of each duplicated variable name declaration. For example, you have this...
Code:
<<code snipped>>
Dim LastRow As Long, TotalN As Double
<<code snipped>>
Dim LastRow As Long, TotalIN As Double, LookupType As Variant, vItem As Variant
<<code snipped>>
Do you see where you have 'LastRow As Long' in each Dim statement... just delete one of them. Variables do not have to be declared before each use of them, they only have to be declared once within the entire procedure (macro in your case). The location for Dim statements is completely unimportant as VB read through the code looking for them before it actually runs the code... why?... because it has to set up memory locations to store the data that is expected to be stored in the variable. That is why I said most people put their Dim statements at the top of the code procedure... VB doesn't care where you put them but putting them at the beginning makes it easy for you to find them (so you can check for duplicates, make sure the variables are declared with the proper data type, and so on).
 
Upvote 0
still doesn't work arrr !
Now it's telling me that there is the same error but with the LookupType I've tried deleting one, or separating the macros since one is a "string" and the other one is a "variant" but still doesnt work...
sorry to cause so much trouble but i'm kind of new to vba
 
Upvote 0
still doesn't work arrr !
Now it's telling me that there is the same error but with the LookupType I've tried deleting one, or separating the macros since one is a "string" and the other one is a "variant" but still doesnt work...
sorry to cause so much trouble but i'm kind of new to vba
Don't take this the wrong way, but I already knew you were kind of new to VBA... some of the things that are causing you trouble shouldn't be as they are basic, foundation type concepts. You might benefit some by stepping back for a short time and either read through a basic VBA programming beginner's book or find an online basic VBA programming beginner's tutorial and get some of the basic programming foundations concepts firmed up a little more in your "memory banks". In any event, I am still willing to try and help you with your current project for a little longer to see if we can get you through your current bottle-neck. I think at this point, so I know what you are working with, that you should post your all of your code (hopefully it is not gigantic in size) so I can see what you are trying to describe to me.
 
Upvote 0
i was planing on doing that but i don't have time, i'll pm you the code, but it is pretty long..
 
Upvote 0
Code:
Sub ReformatingFile()


' msgbox + comfrime macro


Dim Response As Integer


' Displays a message box with the yes and no options.
    Response = MsgBox(prompt:="CAREFUL" & vbNewLine & "this macro will delete alter the original file." & vbNewLine & "Please backup the original before lauching the macro." & vbNewLine & "Do you want to proceed with this macro ?" & vbNewLine & "Created by Rémi Tuyaerts" & vbNewLine & "2013", Title:="INFORMATION")


' Split original into sections


    Dim lLoop As Long, lLoopStop As Long
    Dim rMove As Range, wsNew As Worksheet
     
    Set rMove = ActiveSheet.UsedRange.Columns(1)
    lLoopStop = WorksheetFunction.CountIf(rMove, "Section*")
    For lLoop = 1 To lLoopStop
        Set wsNew = Sheets.Add
        rMove.Find("Section*", rMove.Cells(1, 1), xlValues, _
        xlPart, , xlNext, False).CurrentRegion.Cut _
        Destination:=wsNew.Cells(1, 1)
        wsNew.UsedRange.Columns.AutoFit
    Next lLoop
' Delete orignial sheet


Worksheets("RoughData_139190_cecile_mignon_").Delete




' ask user for month name


Dim monthName As String
monthName = InputBox(prompt:="What month is this file from ?", _
Title:="Please entre name of the month", Default:="January 2013")
    
' insert a column
Dim sht As Worksheet
For Each sht In ActiveWorkbook.Worksheets
sht.Activate
Columns("A:A").Insert Shift:=xlToLeft, CopyOrigin:=xlFormatFromLeftOrAbove
Range("A3").Value = monthName
Dim lRow As Long
With ActiveSheet
lRow = .Range("B" & Rows.Count).End(xlUp).Row
.Range("A3:A" & lRow).FillDown
End With
Next sht


' Creating table of content


Dim ws As Worksheet
Set ws = Sheets.Add
Sheets.Add.Name = "Table_Of_Content"


' Filling TOC
Dim WorkS As Worksheet
    For Each WorkS In ActiveWorkbook.Worksheets
    Sheets("Sheet1").Range("B1").Copy
Sheets("Table_Of_Content").Range("A1").Select
ActiveSheet.Paste
Application.CutCopyMode = False
    Next WorkS


Application.Run "SynthesisVSD"


End Sub


Sub SynthesisVSD()


' adding new sheet for


Dim syn As Worksheet
Dim LastRow As Long, National As Double
Set syn = Sheets.Add
Sheets.Add.Name = "SynthesisVSD"


' copy TOTAL NUMBER OF CALLS


N = Worksheets("Sheet6").Range("B:B").Cells.SpecialCells(xlCellTypeConstants).Count
Range("A1").Value = "Voice"
Cells(1, 1).Font.Bold = True
Cells(1, 1).Font.Size = 15
Range("A2").Value = "Total number of calls"
Range("B2").Value = N - 2


'Copy COST FOR NATIONAL CALLS


ActiveWorkbook.Sheets("Sheet6").Activate
  Const LookupType As String = "Communications nationales"
  LastRow = Cells(Rows.Count, "O").End(xlUp).Row
  National = WorksheetFunction.SumIf(Range("O2:O" & LastRow), LookupType, Range("R2:R" & LastRow))
ActiveWorkbook.Sheets("SynthesisVSD").Activate
Range("A3").Value = "Total cost of National Communications"
Range("B3").Value = National
End Sub
Sub ic()


'Copy COST FOR INTERNATIONAL CALLS
National = WorksheetFunction.SumIf(Range("O2:O" & LastRow), LookupType, Range("R2:R" & LastRow))
TotalIN = 0
ActiveWorkbook.Sheets("Sheet6").Activate
Dim LookupType As Variant, vItem As Variant
LastRow = Cells(Rows.Count, "O").End(xlUp).Row
LookupType = Array("Communications internationales", _
                   "Communications effectuées a l'étranger (ROAMING)", _
                   "Communications recues a l'étranger (ROAMING)")
For Each vItem In LookupType
  National = National + WorksheetFunction.SumIf(Range("O2:O" & LastRow), LookupType, Range("R2:R" & LastRow))
Next
ActiveWorkbook.Sheets("SynthesisVSD").Activate
Range("A4").Value = "Total cost of International Communications"
Range("B4").Value = National


'copy NUMBER OF SMS


N = Worksheets("Sheet7").Range("B:B").Cells.SpecialCells(xlCellTypeConstants).Count
Range("A5").Value = "SMS"
Cells(5, 1).Font.Bold = True
Cells(5, 1).Font.Size = 15
Range("A6").Value = "Total number of sms"
Range("B6").Value = N - 2


' autofit cells


Cells.Select
    Cells.EntireColumn.AutoFit
    Range("A1").Select


' Sorting sheet in acsending order


Dim i As Integer
Dim j As Integer
Dim iAnswer As VbMsgBoxResult


   iAnswer = MsgBox("Sort Sheets in Ascending Order?" & Chr(10) _
     & "Clicking No will sort in Descending Order", _
     vbYesNoCancel + vbQuestion + vbDefaultButton1, "Sort Worksheets")
   For i = 1 To Sheets.Count
      For j = 1 To Sheets.Count - 1


         If iAnswer = vbYes Then
            If UCase$(Sheets(j).Name) > UCase$(Sheets(j + 1).Name) Then
               Sheets(j).Move After:=Sheets(j + 1)
            End If


         ElseIf iAnswer = vbNo Then
            If UCase$(Sheets(j).Name) < UCase$(Sheets(j + 1).Name) Then
               Sheets(j).Move After:=Sheets(j + 1)


            End If
         End If


      Next j
   Next i




End Sub
 
Upvote 0

Forum statistics

Threads
1,214,520
Messages
6,120,008
Members
448,935
Latest member
ijat

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top